Merge branch 'upgrade_proofs_coq_8_11_to_8_16' into 'master'
[why3.git] / bench / check-ce / array_records_mono.mlw
blobf99f367e477b34cbabf5bfa5a6bb847d8c99d253
1 module ArrayRecords
3     use int.Int
4     use map.Map
6     type value = int
7     type index = int
9     function to_rep value: int
10     meta "model_projection" function to_rep
12     type basic_record = {
13         flag [@model_trace:flag] : bool;
14         first_value [@model_trace:first_val] : value;
15         second_value [@model_trace:sec_val] : value;
16     }
18     type array_of_records = private {
19         mutable ghost elts : int -> basic_record;
20         length : int
21     } invariant { 0 <= length }
23     function ([]) (a: array_of_records) (i: int) : basic_record = a.elts i
25     val ([]) (a: array_of_records) (i: int) : basic_record
26         requires { [@expl:index in array bounds] 0 <= i < length a }
27         ensures  { result = a[i] }
29     val ghost function ([<-]) (a: array_of_records) (i: int) (v: basic_record): array_of_records
30         ensures { result.length = a.length }
31         ensures { result.elts = Map.set a.elts i v }
33     val ([]<-) (a: array_of_records) (i: int) (v: basic_record) : unit writes {a}
34         requires { [@expl:index in array bounds] 0 <= i < length a }
35         ensures  { a.elts = Map.set (old a).elts i v }
36         ensures  { a = (old a)[i <- v] }
38 end
40 module Test
42    use int.Int
43    use ArrayRecords
45    let var_overwrite (a: array_of_records) (i: int) : unit
46      requires { a[i] = {flag = true; first_value = 3; second_value = 5}}
47      ensures { a[i].first_value = 42 }
48    =
49      a[i] <- {flag = a[i].flag; first_value= a[i].first_value; second_value = 69};
50      a[i] <- {flag = a[i].flag; first_value= 42; second_value = a[i].second_value};     
51      a[i] <- {flag = a[i].flag; first_value= 23; second_value = a[i].second_value};     
52      a[i] <- {flag = false; first_value= a[i].first_value; second_value = a[i].second_value};     
53      assert {a[i].second_value = 69};
55 end