Changes between Initial Version and Version 1 of Language


Ignore:
Timestamp:
05/16/23 22:57:13 (3 years ago)
Author:
siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Language

    v1 v1  
     1
     2= CIVL-C Language Manual
     3
     4== Qualifiers
     5
     6=== The `$input` and  `$output` type qualifiers
     7
     8The declaration of a variable in the root scope may include the type qualifier `$input`, e.g.,
     9{{{
     10$input int N;
     11}}}
     12This declares the variable to be an input variable, i.e., one which is considered to be an input to the program.
     13Such a variable is initialized with an arbitrary (unconstrained) value of its type.
     14When using symbolic execution to verify a program, such a variable will be assigned a unique symbolic constant of its type.
     15In contrast, variables in the root scope which are not input variables will instead be initialized with the “undefined” value.
     16Reading an undefined value is erroneous. [Note: the model checker attempts to catch such errors but currently
     17does not do so for arrays, which are always initialized with unconstrained values.]
     18In addition, input variables may only be read, never written to; an attempt to write to an input variable is also flagged as an error.
     19
     20Alternatively, it is possible to specify a particular concrete value for an input variable, either on the command line, e.g.,
     21{{{
     22civl verify -inputN=8 ...
     23}}}
     24or by including an initializer in the declaration, e.g.
     25{{{
     26$input int N=8;
     27}}}
     28The protocol for initializing an input variable is the following: if a command line value is specified, it is used.
     29Otherwise, if an initializer is present, it is used.   Otherwise, the variable is assigned an arbitrary value of its type.
     30
     31A variable in the root scope may be declared with `$output` to declare it to be an output variable.
     32Output variables may only be written to, never read.
     33They are used primarily in functional equivalence checking.
     34
     35Input and output variables play a key role when determining whether two programs are functionally equivalent.
     36Two programs are considered functionally equivalent if, whenever they are given the same inputs (i.e., corresponding $input
     37variables are initialized with the same values) they will produce the same outputs (i.e., corresponding $output variables will
     38end up with the same values at termination).
     39
     40=== `$abstract`
     41
     42An abstract function declares a function without a body.  An abstract function is declared using a standard function prototype with the function qualifier `$abstract`, e.g.,
     43{{{
     44  $abstract int f(int x);
     45}}}
     46An abstract function must have a non-void return type and take at least one parameter.   An invocation of an abstract function is an expression and can be used anywhere an expression is allowed.  The interpretation is an "uninterpreted function".    A unique symbolic constant of function type will be created, corresponding to the abstract function, and invocations are represented as applications of the uninterpreted function to the arguments. 
     47
     48=== `$atomic_f`
     49
     50A function is declared atomic using the function qualifier `$atomic_f`, e.g.,
     51{{{
     52$atomic_f int f(int x) {
     53  ...
     54}
     55}}}
     56A call to such a function executes as a single atomic step, i.e., without interleaving from other processes.   Hence, this is only relevant for concurrent programs.  Declaring a function to be atomic is almost equivalent to placing `$atomic{ ... }` around the function body.   The difference is that in the latter case, the call to the function and the execution of the body are executed in two atomic steps, i.e., after activation frame is pushed onto the call stack, another process could execute before the first process obtains the atomic lock and executes its body.   For an atomic function, the entire sequence of events happens in one atomic step.
     57
     58An atomic function must have a definition; in particular, neither a system function nor an abstract function may be declared using `$atomic_f`.
     59
     60=== `$system`
     61
     62A system function is one in which the definition of the function is not provided in CIVL-C code, but is implemented instead in a certain Java class.  A system function is declared by adding the function qualifier `$system` to a function prototype.  Invocation of a system function always takes place in a single atomic step.
     63
     64A system function may have a guard, which is specified in the function contract using a `$executes_when` clause.  Unless constrained by its contract or other qualifiers, a system function may modify the stay in an arbitrary way.
     65
     66=== `$pure`
     67
     68A system or atomic function may be declared to be `$pure`, e.g.,
     69{{{
     70$pure $system double sin(double x);
     71$pure $atomic_f double mysin(double x) {
     72  return  x - x*x*x/6.;
     73}
     74}}}
     75This means that the function is a mathematical function of its arguments only.    I.e., an invocation of the function has no side-effects and the return value depends on the arguments only (if called twice with the same arguments, it will return the same value, regardless of any differences in the state).   The user is responsible for ensuring that a function declared pure actually is pure.    If this is not the case, the model checker may produce incorrect results.
     76
     77== Types
     78
     79=== The Boolean type
     80
     81The boolean type is denoted `_Bool`, as in C. Its values are 0 and 1, which are also denoted by `$false` and `$true`, respectively.
     82
     83=== The integer type
     84
     85There is one integer type, corresponding to the mathematical integers. Currently, all of the C integer types `int`, `long`, `unsigned int`, `short`, etc., are mapped to the CIVL integer type.   [This is expected to change.]
     86
     87=== The real type
     88
     89There is one real type, corresponding to the mathematical real numbers. Currently, all of the C real types `double`, `float`, etc., are mapped to the CIVL real type. [This is expected to change.]
     90
     91=== The process type `$proc`
     92
     93This is a primitive object type and functions like any other primitive C type (e.g., `int`). An object of this type refers to a process. It can be thought of as a process ID, but it is not an integer and cannot be cast to one.  Certain expressions take an argument of `$proc` type and some return something of `$proc` type. The operators `==` and `!=` may be used with two arguments of type `$proc` to determine whether the two arguments refer to the same process.  The constant `$self` has `$proc` type and refers to the process evaluating this expression;  constant `$proc_null` has `$proc` type and refers to no process.
     94
     95=== The scope type `$scope`
     96
     97An object of this type is a reference to a dynamic scope.
     98Several constants, expressions, and functions dealing with the $scope type are also provided.
     99The `$scope` type is like any other object type.
     100It may be used as the element type of an array, a field in a structure or union, and so on.
     101Expressions of type `$scope` may occur on the left or right-hand sides of assignments and as arguments in function calls just like any other expression.
     102Two different variables of type `$scope` may be aliased, i.e., they may refer to the same dynamic scope.
     103
     104=== Domain types: `$domain` and `$domain(n)`
     105
     106A domain type is used to represent a set of tuples of integer values.
     107Every tuple in a domain object has the same arity (i.e., number of components).
     108The arity must be at least 1, and is called the dimension of the domain object.
     109For each integer constant expression n, there is a type `$domain(n)`, representing domains of dimension n.
     110The universal domain type, denoted `$domain`, represents domains of all positive dimensions, i.e., it is the union over all n ≥ 1 of `$domain(n)`.
     111In particular, each `$domain(n)` is a subtype of `$domain`.
     112There are expressions for specifying domain values.
     113Certain statements use domains, such as the “CIVL-for” loop `$for`.
     114
     115=== The range type `$range`
     116
     117An object of this type represents an ordered set of integers.
     118Ranges are typically used as a step in constructing domains.
     119They can also be used in quantified expressions to specify the domain of a bound variable (see `$forall` and `$exists`).
     120
     121== Expressions
     122
     123=== Boolean expressions
     124
     125CIVL-C provides the boolean constants`$true` and `$false`, which are simply defined as 1 and 0, respectively.
     126CIVL-C is, after all, an extension of C.
     127A program may also include the standard C library header file `stdbool.h`, which defines `true` and `false` in the exact same way.
     128
     129In addition to the standard logical operators `&&`, `||`, and `!`, CIVL-C provides `=>` (implies).
     130`p => q` is equivalent to `!(p) || q` (and has the same short-circuit semantics).
     131
     132A universally quantified formula has the form
     133
     134  `$forall` `(` ''variable-decls'' (`;` ''variable-decls'' )* (`|` ''restriction'')? `)` ''expr''
     135
     136where ''variable-decls'' has one of the forms
     137
     138  ''type'' ''identifier'' (`,` ''identifier'')*
     139
     140  ''type'' ''identifier'' `:` ''range''
     141
     142where ''type'' is a type name (e.g., `int` or `double`), ''identifier'' is the name of the bound variable,
     143''restriction'' is a formula (boolean expression) which expresses some restriction on the values that the bound variable can take,
     144''range'' is an expression of `$range` type, and ''expr'' is a formula.
     145The universally quantified formula holds iff for all values assignable to the bound variable for which the restriction holds, the formula expr holds.
     146
     147The syntax for existential quantification is the same, with `$exists` in place of `$forall`. 
     148
     149Examples:
     150{{{
     151int a[3], b[3][2];
     152int main() {
     153  int n=3, m=2;
     154  $assert($forall (int i | 0<=i && i<n) a[i]==0); // all elements of a are 0
     155  $assert($forall (int i: 0..n-1) a[i]==0); // same as above
     156  $assert($forall (int i: 0..n-1 | i%2==0) a[i]==0); // even elements are 0
     157  $assert($forall (int i: 0..n-1#2) a[i]==0); // same as above
     158  $assert($forall (int i: 0..n-1; int j: 0..m-1) b[i][j]==0); // all elements of b are 0
     159  $assert($forall (int i: 0..n-1; int j | 0<=j && j<m) b[i][j]==0); // same
     160  $assert($forall (int i: 0..n-1; int j: 0..m-1 | i<j ) b[i][j]==0); // lower triangle is 0
     161  $assert($forall (int i,j | 0<=i && i<n && 0<=j && j<m) b[i][j]==0); // all elements of b are 0
     162  $assert($exists (int i | 0<=i && i<n) a[i]==0); // existential: some element of a is 0
     163  $assert($forall (int i: 0..n-1) $exists (int j: 0..i) a[j]<=a[i]); // nested quantification
     164}
     165}}}
     166
     167=== Domain literals
     168
     169An expression of the form
     170
     171  `(``$domain``)`  `{` ''r1'' `,` ... `,` ''rn'' `}`
     172
     173where ''r1'', . . . , ''rn'' are ''n'' expressions of type `$range`, is a ''Cartesian domain expression''.
     174It represents the domain of dimension ''n'' which is the Cartesian product of the ''n'' ranges,
     175i.e., it consists of all ''n''-tuples (''x1'',...,''xn'') where ''x1'' ∈ ''r1'', ..., ''xn'' ∈ ''rn''.
     176The order on the domain is the dictionary order on tuples.
     177The type of this expression is `$domain(n)`.
     178When a Cartesian domain expression is used to initialize an object of domain type, the `($domain)` may be omitted. For example:
     179{{{
     180$domain(3) dom = { 0 .. 3, r2, 10 .. 2 # -2 };
     181}}}
     182
     183
     184=== `$here`
     185Expression of type `$scope`, evaluating to the dynamic scope in which the evaluation takes place.
     186
     187=== `$proc_null`
     188The null process constant.  Similar to the NULL pointer, this gives an object of `$proc` type a defined value, and can be used in `==` and `!=` expressions.  It cannot be used as the argument to `$wait` or `$waitall`.
     189
     190=== `$root`
     191Constant of type `$scope`, the root dynamic scope.
     192
     193=== Range literals
     194
     195An expression of the form `lo .. hi` where `lo` and `hi` are integer expressions, represents the range consisting of the integers `lo`, `lo` + 1, ..., `hi` (in that order).
     196An expression of the form `lo .. hi # step`, where `lo`, `hi`, and `step` are integer expressions is interpreted as follows.
     197If `step` is positive, it represents the range consisting of `lo`, `lo` + `step`, `lo` + 2 ∗ `step`, …, up to and possibly including `hi`.
     198To be precise, the infinite sequence is intersected with the set of integers less than or equal to `hi`.
     199If `step` is negative, the expression represents the range consisting of `hi`, `hi` + `step`, `hi` + 2 ∗ `step`, . . ., down to and possibly including `lo`.
     200Precisely, the infinite sequence is intersected with the set of integers greater than or equal to `lo`.
     201
     202=== `$scopeof`
     203
     204Given any left-hand-side expression ''expr'', the expression `$scopeof(`''expr''`)` evaluates to the dynamic scope containing the object specified by ''expr''.
     205The following example illustrates the semantics of the `$scopeof` operator. All of the assertions hold:
     206{{{
     207{
     208  $scope s1 = $here;
     209  int x;
     210  double a[10];
     211  {
     212    $scope s2 = $here;
     213    int *p = &x;
     214    double *q = &a[4];
     215    assert($scopeof(x)==s1);
     216    assert($scopeof(p)==s2);
     217    assert($scopeof(*p)==s1);
     218    assert($scopeof(a)==s1);
     219    assert($scopeof(a[5])==s1);
     220    assert($scopeof(q)==s2);
     221    assert($scopeof(*q)==s1);
     222  }
     223}
     224}}}
     225
     226=== Scope relational expressions
     227
     228Let `s1` and `s2` be expressions of type `$scope`. The following are all CIVL-C expressions of boolean type:
     229
     230* `s1 == s2`. Holds iff `s1` and `s2` refer to the same dynamic scope.
     231* `s1 != s2`. Holds iff `s1` and `s2` refer to different dynamic scopes.
     232* `s1 <= s2`. Holds iff `s1` is equal to or a descendant of `s2`, i.e., `s1` is equal to or contained in `s2`.
     233* `s1 < s2`. Holds iff `s1` is a strict descendant of `s2`, i.e., `s1` is contained in `s2` and is not equal to `s2`.
     234* `s1 > s2`. Equivalent to `s2 < s1`.
     235* `s1 >= s2`. Equivalent to `s2 <= s1`.
     236
     237Each of these expressions is erroneous if `s1` or `s2` is undefined.  This error is reported by the model checker.
     238
     239=== `$self`
     240
     241This expression of `$proc` type returns a reference to the process which is evaluating this expression.  It provides a way for code to obtain the identity of the process executing the code.
     242
     243== Statements
     244
     245
     246=== `$atomic`
     247
     248=== `$choose`
     249
     250=== `$for`
     251
     252=== `$parfor`
     253
     254=== `$spawn`
     255
     256=== `$when`
     257
     258
     259== Functions
     260
     261=== `$assert`
     262
     263=== `$assume`
     264
     265=== `$assume_push`
     266
     267=== `$assume_pop`
     268
     269=== `$choose_int`
     270
     271=== `$default_value`
     272
     273=== `$elaborate_domain`
     274
     275=== `$exit`
     276
     277=== `$free`
     278
     279=== `$havoc`
     280
     281=== `$hidden`
     282
     283=== `$hide`
     284
     285=== `$is_derefable`
     286
     287=== `$is_terminated`
     288
     289=== `$local_end`
     290
     291=== `$local_start`
     292
     293=== `$malloc`
     294
     295=== `$pathCondition`
     296
     297=== `$pow`
     298
     299`$pow(double, double)`
     300
     301=== `$reveal`
     302
     303=== `$wait` and `$waitall`
     304
     305=== `$yield`
     306
     307
     308== Macros
     309
     310
     311=== `$elaborate`
     312
     313
     314
     315
     316== Contract Annotations
     317
     318clauses
     319
     320=== The `depends_on` clause
     321
     322`\nothing`
     323
     324=== The `executes_when` clause