-
Notifications
You must be signed in to change notification settings - Fork 0
/
Klon.dfy
5738 lines (4425 loc) · 167 KB
/
Klon.dfy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
type Mapping = map<Object,Object>
///shoujld thsi be m.KEys or m.ks...
predicate OrigMapOK(m : Mapping)
{
&& (forall x <- m.Keys, oo <- x.AMFO :: oo in m.Keys)
&& (forall x <- m.Keys :: x.region.Heap? == m[x].region.Heap?)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in x.AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in m.Keys)
&& (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == m[x].region.owner )
&& (forall x <- m.Keys, oo <- x.AMFO :: m[oo] in m[x].AMFO)
// && forall x <- m.Keys :: (not(inside(x,o)) ==> (m[x] == x))x
}
predicate ExpandedMapOK(m : Mapping)
{
&& (forall x <- m.Keys, oo <- x.AMFO :: oo in m.Keys)
&& (forall x <- m.Keys :: x.region.Heap? == m[x].region.Heap?)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in x.AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in m.Keys)
&& (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == m[x].region.owner )
&& (forall x <- m.Keys, oo <- x.AMFO :: m[oo] in m[x].AMFO)
&& (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO) //NEW BIT
//also needs the first line abofeE= -- x.AMFO in m.Keys
// && forall x <- m.Keys :: (not(inside(x,o)) ==> (m[x] == x))
&& (forall x <- m.Keys | x.region.Heap? :: x.extra <= x.AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.extra <= m.Keys)
&& (forall x <- m.Keys, xo <- x.extra :: xo in m.Keys)
&& (forall x <- m.Keys, xo <- x.extra :: m[xo] in m[x].extra)
&& (forall x <- m.Keys :: (set xo <- x.extra :: m[xo]) == m[x].extra)
}
//streamlined MapOK - notably pulled out AMDO & extra to one line each
//
predicate MapOK(m : Mapping)
{
&& (forall k <- m.Keys :: k.AMFO <= m.Keys)
&& (forall k <- m.Keys :: (set oo <- k.AMFO :: m[oo]) == m[k].AMFO)
&& (forall x <- m.Keys :: x.region.Heap? == m[x].region.Heap?)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in x.AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.region.owner in m.Keys)
&& (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == m[x].region.owner )
//&& (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO) //NEW BIT
//also needs the first line abofeE= -- x.AMFO in m.Keys
// && forall x <- m.Keys :: (not(inside(x,o)) ==> (m[x] == x))
///////// && (forall x <- m.Keys, oo <- x.AMFO :: m[oo] in m[x].AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.extra <= x.AMFO)
&& (forall x <- m.Keys | x.region.Heap? :: x.extra <= m.Keys)
&& (forall x <- m.Keys, xo <- x.extra :: xo in m.Keys)
&& (forall x <- m.Keys, xo <- x.extra :: m[xo] in m[x].extra)
&& (forall k <- m.Keys :: (set oo <- k.extra :: m[oo]) == m[k].extra)
}
function MapKV(m : Mapping, x : Object, v : Object) : (r : Mapping)
reads x`fields, x`fieldModes
requires AllMapEntriesAreUnique(m)
ensures AllMapEntriesAreUnique(r)
requires MapOK(m)
ensures MapOK(r)
requires //the below should be a predicate (from MapKV)b or MapOK??? or MapWIthKVWouleBeOK?
&& v !in m.Values
&& x !in m.Keys
&& COK(x,m.Keys+{x})
&& x.Ready() && v.Ready()
&& (forall oo <- (x.AMFO - {x}) :: oo in m.Keys)
&& (x.region.Heap? == v.region.Heap?)
&& (x.region.Heap? ==> x.region.owner in x.AMFO)
&& (x.region.Heap? ==> x.region.owner in m.Keys)
&& (forall oo <- x.owners() :: oo in m.Keys && m[oo] in v.AMFO)
&& (x.region.Heap? ==> x.region.owner in (x.AMFO - {x}))
&& (x.region.Heap? ==> m[x.region.owner] == v.region.owner)
&& (forall xo <- x.extra :: xo in m.Keys)
&& (forall xo <- x.extra :: m[xo] in v.extra)
// && (x.AMFO <= m.Keys) //how the FUCK as the EVER POSSIBLE
&& ((set oo <- x.owners() :: m[oo]) == v.owners()) //NEW BIT ///note that x can't be in AMFO FUCKER
&& (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO) //NEW BIT
requires mapThruMappingKV(x.AMFO, m, x, v) == v.AMFO
requires mapThruMappingKV(x.extra, m, x, v) == v.extra
{
reveal COK();
var r := m[x:=v];
assert COK(x,m.Keys+{x});
assert MapOK(m);
assert AllMapEntriesAreUnique(m);
assert x !in m.Keys;
assert v !in m.Values;
assert r.Keys == m.Keys + {x};
assert m.Keys <= r.Keys;
assert forall k <- m.Keys :: k in r.Keys;
assert forall k <- r.Keys :: (k in m.Keys) || (k == x);
assert forall k <- r.Keys ::
if (k in m.Keys) then r[k] == m[k] else r[k] == v;
///
//copied from putINside, which seems WAYY to much duplication
// assert (forall xx <- m.Keys :: (set xo <- xx.extra :: m[xo]) == m[xx].extra);
// assert (forall xx <- m.Keys :: (set xo <- xx.extra :: r[xo]) == r[xx].extra);
// assert (forall xx <- r.Keys :: (set xo <- xx.extra :: r[xo]) == r[xx].extra);
//
//
//
// assert (forall xo <- x.extra :: xo in r.Keys);
// assert (forall xo <- x.extra :: r[xo] in r[x].extra);
// assert (forall xo <- x.extra :: xo in r.Keys);
// assert (forall xo <- x.extra :: r[xo] in r[x].extra);
//
// assert (forall xx <- {x}, xo <- xx.extra :: xo in r.Keys);
// assert (forall xx <- {x}, xo <- xx.extra :: r[xo] in r[xx].extra);
// assert (forall xx <- {x}, xo <- xx.extra :: r[xo] in r[xx].extra);
//
// assert (forall xx <- m.Keys :: (set xo <- xx.extra :: m[xo]) == m[xx].extra);
// assert (forall xx <- r.Keys :: (set xo <- xx.extra :: r[xo]) == r[xx].extra); //EXTRA BIT :-)
// was going to work on this bit...
// assert (forall xx <- m.Keys :: (set oo <- xx.AMFO :: m[oo]) == m[xx].AMFO); //NEW BIT
// assert (forall xx <- m.Keys :: (set oo <- xx.AMFO :: r[oo]) == r[xx].AMFO); //NEW BIT
// assert (forall xx <- {x} :: (set oo <- xx.AMFO :: r[oo]) == r[xx].AMFO); //NEW BIT
// assert r.Keys == m.Keys + {x};
// assert (forall xx <- r.Keys :: (set oo <- xx.AMFO :: r[oo]) == r[xx].AMFO); //NEW BIT
// assert (forall x <- r.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO) by {
// assert (forall oo <- x.AMFO :: r[oo] in r[x].AMFO);
// assert (forall x <- m.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO);
// assert r.Keys == m.Keys + {x};
// assert (forall x <- r.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO);
// }
// assert (forall x <- r.Keys | x.region.Heap? :: r[x.region.owner] == r[x].region.owner) by {
// assert (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == r[x].region.owner);
// assert (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == r[x].region.owner);
// assert r.Keys == m.Keys + {x};
// assert (forall x <- r.Keys | x.region.Heap? :: r[x.region.owner] == r[x].region.owner);
// }
assert (forall x <- r.Keys :: x.region.Heap? == r[x].region.Heap?) by {
assert (forall x <- m.Keys :: x.region.Heap? == r[x].region.Heap?);
assert r.Keys == m.Keys + {x};
assert (forall x <- r.Keys :: x.region.Heap? == r[x].region.Heap?);
}
assert (&& (forall x <- m.Keys, xo <- x.extra :: xo in m.Keys)
&& (forall x <- r.Keys, xo <- x.extra :: r[xo] in r[x].extra)) by {
assert (forall x <- m.Keys, xo <- x.extra :: m[xo] in m[x].extra);
assert forall k <- r.Keys ::
if (k in m.Keys) then r[k] == m[k] else r[k] == v;
assert (forall x <- m.Keys, xo <- x.extra :: r[xo] in m[x].extra);
assert r.Keys == m.Keys + {x};
assert x in r.Keys;
assert (forall xo <- x.extra :: m[xo] in v.extra);
assert (forall x <- r.Keys, xo <- x.extra :: r[xo] in r[x].extra);
}
assert (forall x <- r.Keys :: (set oo <- x.extra :: r[oo]) == r[x].extra)
by {
assert MapOK(m);
assert (forall x <- m.Keys :: (set oo <- x.extra :: m[oo]) == m[x].extra);
assert (forall k <- r.Keys :: if (k in m.Keys) then r[k] == m[k] else r[k] == v);
assert (forall x <- m.Keys :: (set oo <- x.extra :: r[oo]) == r[x].extra);
// assert (set oo <- (x.extra) :: m[oo]) == v.extra;
// assert (set oo <- (x.extra) :: r[oo]) == v.extra;
assert r[x] == v;
assert r.Keys == m.Keys + {x};
assert (forall x <- r.Keys :: (set oo <- x.extra :: r[oo]) == r[x].extra);
}
assert FUCKA: (forall x <- r.Keys :: (set oo <- x.extra :: r[oo]) == r[x].extra);
assert (forall x <- r.Keys | x.region.Heap? :: r[x.region.owner] == r[x].region.owner )
by {
assert MapOK(m);
assert (forall x <- m.Keys | x.region.Heap? :: m[x.region.owner] == m[x].region.owner );
assert forall k <- r.Keys ::
if (k in m.Keys) then r[k] == m[k] else r[k] == v;
assert (forall x <- m.Keys | x.region.Heap? :: r[x.region.owner] == r[x].region.owner );
assert x.region.Heap? ==> (r[x.region.owner] == r[x].region.owner);
assert (forall x <- r.Keys | x.region.Heap? :: r[x.region.owner] == r[x].region.owner );
}
assert (forall x <- r.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO)
by {
assert MapOK(m);
assert (forall x <- m.Keys, oo <- x.AMFO :: m[oo] in m[x].AMFO);
assert forall k <- r.Keys ::
if (k in m.Keys) then r[k] == m[k] else r[k] == v;
assert (forall x <- m.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO);
assert (forall oo <- x.AMFO - {x} :: r[oo] in v.AMFO);
assert r[x] == v;
assert (x in x.AMFO) && (v in v.AMFO) && (r[x] in r[x].AMFO);
assert (forall x <- r.Keys, oo <- x.AMFO :: r[oo] in r[x].AMFO);
}
assert (forall x <- r.Keys :: (set oo <- x.AMFO :: r[oo]) == r[x].AMFO)
by {
assert MapOK(m);
assert (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO);
assert (forall k <- r.Keys :: if (k in m.Keys) then r[k] == m[k] else r[k] == v);
assert (forall x <- m.Keys :: (set oo <- x.AMFO :: r[oo]) == r[x].AMFO);
// assert (set oo <- x.AMFO :: r[oo]) == r[x].AMFO;
assert mapThruMappingKV(x.AMFO, m, x, v) == v.AMFO;
assert ((set oo <- x.AMFO :: r[oo]) == v.AMFO);
assert (forall k <- {x} :: (set oo <- k.AMFO :: r[oo]) == v.AMFO);
assert r[x] == v;
assert r.Keys == m.Keys + {x};
assert ( x in x.AMFO) && (v in v.AMFO) && (r[x] in r[x].AMFO);
assert (set oo <- x.AMFO :: r[oo]) == v.AMFO;
assert (forall k <- m.Keys+{x} :: (set oo <- k.AMFO :: r[oo]) == r[k].AMFO);
assert (forall x <- r.Keys :: (set oo <- x.AMFO :: r[oo]) == r[x].AMFO);
}
assert AllMapEntriesAreUnique(r) by {
reveal UniqueMapEntry();
assert AllMapEntriesAreUnique(m);
assert forall i <- m.Keys :: UniqueMapEntry(m, i);
assert x !in m.Keys;
assert v !in m.Values;
assert forall i <- (m.Keys+{x}) :: UniqueMapEntry(r, i);
assert (m.Keys+{x}) == r.Keys;
assert forall i <- (r.Keys) :: UniqueMapEntry(r, i);
assert AllMapEntriesAreUnique(r);
}
assert MapOK(r) by {
reveal FUCKA;
assert (forall x <- r.Keys :: (set oo <- x.extra :: r[oo]) == r[x].extra);
}
r
}//MapKV
lemma MapKVOK(m : Mapping, x : Object, v : Object, r : Mapping)
requires AllMapEntriesAreUnique(m)
ensures AllMapEntriesAreUnique(r)
requires MapOK(m)
ensures MapOK(r)
requires //the below should be a predicate (from MapKV)
&& x !in m.Keys
&& v !in m.Values
//&& COK(x,m.Keys)
&& x.Ready() && v.Ready()
&& (forall oo <- (x.AMFO - {x}) :: oo in m.Keys)
&& (x.region.Heap? == v.region.Heap?)
&& (x.region.Heap? ==> x.region.owner in x.AMFO)
&& (x.region.Heap? ==> x.region.owner in m.Keys)
&& (forall oo <- (x.AMFO - {x}) :: oo in m.Keys && m[oo] in v.AMFO)
&& (x.region.Heap? ==> x.region.owner in (x.AMFO - {x}))
&& (x.region.Heap? ==> m[x.region.owner] == v.region.owner)
&& (x.region.Heap? ==> x.extra <= x.AMFO)
&& (forall xo <- x.extra :: xo in m.Keys)
&& (forall xo <- x.extra :: m[xo] in v.extra)
&& (x.AMFO <= m.Keys) /// implies x in m.Keys... which is WRONG
&& ((set oo <- x.AMFO :: m[oo]) == v.AMFO) //NEW BIT
&& (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO) //NEW BIT
requires r == MapKV(m,x,v)
ensures r.Keys == m.Keys + {x}
ensures forall i <- m.Keys :: i in r.Keys
ensures forall i <- m.Keys :: m[i] == r[i]
ensures forall i <- r.Keys :: if (i == x) then (r[i] == v) else (r[i] == m[i])
{
reveal COK();
var r := m[x:=v];
// assert COK(x,m.Keys);
assert MapOK(m);
assert AllMapEntriesAreUnique(m);
assert x !in m.Keys;
assert v !in m.Values;
assert r.Keys == m.Keys + {x};
assert m.Keys <= r.Keys;
assert forall k <- m.Keys :: k in r.Keys;
assert forall k <- r.Keys :: (k in m.Keys) || (k == x);
assert forall k <- r.Keys ::
if (k in m.Keys) then r[k] == m[k] else r[k] == v;
}
datatype Map = Map(
m : Mapping, //m : Mapping
ks : set<Object>, //ks - set, keys of the mapping (must be m.Keys, subset of oHeap)
vs : set<Object>, //vs - set, values or the mapping (must be m.Values, subset of oHeap + ns)
o : Object, //o - Owner within which the clone is being performaed, in oHeap
// p : Object, // Owner of the new (target) clone. needs to be inside the source object's movement
oHeap : set<Object>, //oHeap - original (sub)heap contianing the object being cloned and all owners and parts
ns : set<Object>) //ns - new objects (must be !! oHeap, vs <= oHeap + ns
{
// general rule: where possible, work with ks and vs rther than m.Keys & m.Values...
// that's the point of setting this up, right?
predicate fromold(prev : Map)
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
reads prev.oHeap`fields, prev.oHeap`fieldModes
reads prev.ns`fields, prev.ns`fieldModes
{
reveal calid(), calidObjects(), calidOK(), calidMap(), calidSheep();
// old(from(prev))
&& calid() //should these be requirements?
// && old(prev.calid())
&& mapGEQ(m, prev.m)
&& ks >= prev.ks
&& vs >= prev.vs
&& o == prev.o
&& oHeap == prev.oHeap
&& ns >= prev.ns
}
predicate from(prev : Map)
// should this be unique or not?
// m.from(prev) assuming prev.MapOK, then I',m Map(OK) and a a "strict but improper extension"
// strict - thijngs like oHeap can't change
// improper - could be exactly the same as prev
//
// if most things are OK, given xown, xm := foo(own, m);
// then we should have xm.from(m); I THINK??
//
/// what's really annoy6ing is: should I keep track of the first from?
// cos usually that's what I need to prove.
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
reads prev.oHeap`fields, prev.oHeap`fieldModes
reads prev.ns`fields, prev.ns`fieldModes
// requires calid()
// requires prev.calid()
{
reveal calid(), calidObjects(), calidOK(), calidMap(), calidSheep();
&& calid() //should these be requirements?
// && prev.calid() //currently YES because the underlyign thing will require calid and reutnr calid
&& mapGEQ(m, prev.m)
&& ks >= prev.ks
&& vs >= prev.vs
&& o == prev.o
&& oHeap == prev.oHeap
&& ns >= prev.ns
}
static lemma fromityH(a : Object, context : set<Object>, prev : Map, next: Map)
requires prev.calid()
requires next.calid()
requires next.from(prev)
requires context <= prev.oHeap
requires COK(a,context)
ensures context <= next.oHeap
ensures COK(a,next.oHeap)
{
COKWiderContext2(a,context,next.oHeap);
}
twostate predicate allUnchangedExcept(except : set<Object> := {})
reads vs, ks, o, oHeap
{
&& unchanged(vs - except)
&& unchanged(ks - except)
&& unchanged({o} - except)
&& unchanged(oHeap - except)
}
opaque function at(k : Object) : (v : Object)
//return value corresponding to key k
//k must be in the map
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
requires calid()
requires k in ks
//requires reveal calid(); reveal calidObjects(); ks == m.Keys
//requires k in m.Keys
ensures k in ks
ensures k in m.Keys //to guard the next one
ensures v == m[k]
// ensures k == atV(v)
{ reveal calid(); reveal calidObjects();
assert k in m.Keys;
m[k] }
method superTRUMP(k : Object, v : Object)
requires COK(k, {k})
requires CallOK({}, {k})
requires CallOK({k})
requires ExtraIsExtra({},{k})
requires AllTheseOwnersAreFlatOK(k.AMFO)
requires AllTheseOwnersAreFlatOK({}, k.AMFO + {})
{
var jd := new Object.cake( map[], k, {k}, "hello");
assert jd !in oHeap;
Vance(jd);
}
method Vance(v : Object)
requires v !in oHeap
{}
lemma habeusKeyus(k : Object, v : Object)
requires calid()
//requires v in vs
requires (k in ks) ==> (m[k] == v)
// requires k in ks
// requires k in m.Keys //to guard the next one
// ensures v in ns ==> k in ks
// ensures k !in ks ==> v !in ns
ensures (v !in ns) && (v in vs) ==> v in oHeap
{
reveal calid();
assert calid();
reveal calidObjects();
assert calidObjects();
reveal calidMap();
assert calidMap();
assert MapOK(m);
assert ns <= vs;
if (v in ns) {
assert v in vs;
assert gotV(v);
assert AllMapEntriesAreUnique(m);
AValueNeedsAKey(v, m);
} else {
assert v !in ns;
}
}
static lemma roundTrip1(k : Object, v : Object, m : Map)
requires m.calid()
requires m.got(k)
requires m.at(k) == v
ensures m.atV(v) == k
{
reveal m.calid();
assert m.calid();
reveal m.calidObjects();
assert m.calidObjects();
reveal m.calidMap();
assert m.calidMap();
assert MapOK(m.m);
assert AllMapEntriesAreUnique(m.m);
// reveal atV();
// reveal at();
reveal UniqueMapEntry();
assert m.at(k) == v; //why is this needed?
assert m.m[k] == v;
assert forall i <- m.m.Keys :: UniqueMapEntry(m.m, i);
assert k in m.m.Keys;
assert UniqueMapEntry(m.m, k);
assert m.atV(v) == k;
}
static lemma roundTrip2(k : Object, v : Object, m : Map)
requires m.calid()
requires m.gotV(v)
requires m.atV(v) == k
ensures m.at(k) == v
{
reveal m.calid();
assert m.calid();
reveal m.calidObjects();
assert m.calidObjects();
reveal m.calidMap();
assert m.calidMap();
assert MapOK(m.m);
assert AllMapEntriesAreUnique(m.m);
}
opaque ghost function atV(v : Object) : (k : Object)
//return key corresponding to value v
//v must be in the map
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
requires calid()
requires v in vs
//requires reveal calid(); reveal calidObjects(); ks == m.Keys
//requires k in m.Keys
ensures k in ks
ensures k in m.Keys //to guard the next one
ensures v == m[k]
{ reveal calid(); reveal calidObjects(); reveal calidMap();
assert calid(); assert calidObjects(); assert calidMap();
assert v in m.Values;
AValueNeedsAKey(v, m);
assert AllMapEntriesAreUnique(m);
var k' :| k' in m.Keys && m[k'] == v;
k' }
opaque predicate {:onleee} got(k : Object) : (g : bool)
//is k in the map?
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
requires calid()
ensures g == (k in ks)
ensures g == (k in m.Keys) //DO I WANT THIS?
{
reveal calid();
assert calid();
reveal calidObjects();
assert calidObjects();
k in ks
}
opaque predicate gotV(v : Object) : (g : bool)
//is v a value in the map?
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
requires calid()
ensures g == (v in vs)
ensures g == (v in m.Values) //DO I WANT THIS?
{
reveal calid();
assert calid();
reveal calidObjects();
assert calidObjects();
v in vs
}
opaque function {:isolate_assertions} putInside(k : Object, v : Object) : (r : Map)
//put k -> v into map, k inside o
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes, v`fields, v`fieldModes
requires calid()
requires k in oHeap
requires k !in ks
requires k !in m.Keys
requires v !in oHeap
requires v !in ns
requires v !in vs
requires v !in m.Values
requires COK(k, oHeap)
requires COK(v, oHeap+ns+{v})
requires ks <= oHeap
requires k.owners() <= ks //need to update - all my owners EXCEPT ME!
requires k.owners() <= m.Keys
requires v.owners() <= oHeap+ns //need to hae proceessed all owners first
// requires v in (oHeap + ns) // should be a SEPERATIJG COJUNCTION (Below)
// requires ((v in oHeap) != (v in ns)) //NOPE for now put it in ns
requires k.region.Heap? == v.region.Heap?
requires k.region.Heap? ==> v.region.Heap? && (k.region.owner in m.Keys) && (m[k.region.owner] == v.region.owner)
requires forall ko <- k.owners() :: ko in m.Keys
requires forall ko <- k.owners() :: m[ko] in v.AMFO
// requires mapThruMap(k.owners(), this) == (v.AMFO - {v})
requires ((set oo <- k.owners() :: m[oo]) == v.owners())
requires mapThruMapKV(k.AMFO, this, k, v) == v.AMFO
requires forall kx <- k.extra :: kx in m.Keys
requires forall kx <- k.extra :: m[kx] in v.extra
// requires k.region.Heap? ==> (k.region.owner in m && m[k.region.owner] == v.region.owner)
// requires reveal calid(); (calid() && k.region.Heap?) ==> (got(k.region.owner) && (at(k.region.owner) == v.region.owner))
//requires fresh(v)
requires inside(k, o)
requires v.fieldModes == k.fieldModes
ensures r == Map(m[k:=v], ks+{k}, vs+{v}, o, oHeap, ns+{v})
ensures r.m.Keys == r.ks
ensures r.m.Values == r.vs
ensures v in r.ns
ensures k in r.ks && r.m[k] == v
ensures COK(v, r.oHeap+r.ns)
ensures k in r.m.Keys
ensures v in r.m.Values
ensures r.m == m[k:=v]
ensures mapLEQ(m, r.m)
ensures r.calid()
ensures r.from(this)
ensures AllMapEntriesAreUnique(this.m)
ensures r.m == MappingPlusOneKeyValue(this.m,k,v)
{
reveal calid();
assert calid();
reveal calidObjects();
assert calidObjects();
reveal calidOK();
assert calidOK();
assert ks == m.Keys;
assert calidMap();
reveal calidMap();
assert calidSheep();
reveal calidSheep();
assert MapOK(m);
assert CallOK(oHeap);
assert COK(k, oHeap);
assert COK(v, oHeap+ns+{v});
reveal COK();
assert AllMapEntriesAreUnique(m);
reveal calid(); assert calid();
var rv := Map(m[k:=v], ks+{k}, vs+{v}, o, oHeap, ns+{v});
reveal calidMap(); assert calidMap(); assert MapOK(m);
assert MapKV(m,k,v) == m[k:=v] by { reveal calidMap(); assert calidMap(); assert MapOK(m);}
assert rv.m == MapKV(m,k,v);
assert oXn: oHeap !! ns by { assert calid(); assert calidObjects(); reveal calidObjects();}
assert COK(v, rv.oHeap+rv.ns) by {
assert COK(v, oHeap+ns+{v}); // from reqs
assert rv.oHeap == oHeap;
assert rv.ns == ns+{v};
assert rv.oHeap+rv.ns == oHeap+ns+{v};
assert COK(v, rv.oHeap+rv.ns);
}
assert rv.calidObjects() by {
reveal rv.calidObjects();
assert rv.ks == rv.m.Keys;
assert rv.vs == rv.m.Values;
assert rv.o in rv.oHeap;
assert rv.ks <= rv.oHeap;
assert rv.ns !! rv.oHeap by {
assert ns !! oHeap by { reveal oXn; }
assert v !in oHeap;
assert {v} !! oHeap;
assert (ns + {v}) !! oHeap;
assert rv.oHeap == oHeap;
assert (ns + {v}) !! rv.oHeap;
assert rv.ns == ns+{v};
assert rv.ns !! rv.oHeap;
}
assert rv.vs <= rv.ns + oHeap;
assert rv.calidObjects();
}
assert v !in vs; // from reqs
assert vs == m.Values by {
assert calid();
reveal calid();
assert calidObjects();
reveal calidObjects();
assert vs == m.Values;
}
assert v !in m.Values;
assert rv.calidOK() by {
reveal rv.calidOK();
reveal rv.calidObjects();
assert COK(rv.o, rv.oHeap);
assert CallOK(rv.oHeap);
CallOKfromCOK(k, oHeap);
assert CallOK(ks, oHeap);
CallOKtoSubset(ks, oHeap);
CallOKWiderFocus(ks, {k}, oHeap);
assert CallOK(rv.ks, rv.oHeap);
assert oHeap+ns+{v} == rv.oHeap+rv.ns;
assert COK(v, rv.oHeap+rv.ns);
// CallOKWiderContext({v}, rv.oHeap, rv.ns); //unneeded?
// CallOKtoSubset(rv.vs, rv.oHeap+rv.ns); //unneeded?
assert rv.vs <= rv.ns + oHeap;
assert CallOK(vs, oHeap+ns);
CallOKWiderContext(vs, oHeap+ns, {v});
assert COK(v,oHeap+ns+{v}); //reqs
CallOKfromCOK(v, oHeap+ns+{v}); //could subsume within COK?> (or not0)
CallOKWiderFocus(vs, {v}, oHeap+ns+{v}); //version just adding one?
assert vs+{v} == rv.vs;
assert CallOK(rv.vs, rv.oHeap+rv.ns);
assert ns+{v} == rv.ns;
CallOKWiderContext(ns,oHeap+ns,{v}); //is it worth cobinging these also
CallOKWiderFocus(ns,{v},oHeap+ns+{v});
assert CallOK(rv.ns, rv.oHeap+rv.ns);
reveal rv.calidOK(); assert rv.calidOK();
}
// reveal rv.calidMap();
// assert rv.calidMap() by {
reveal rv.calidMap();
assert MapOK(rv.m) by {
assert MapOK(m);
assert COK(k, oHeap);
reveal COK();
assert rv.ks == ks + {k};
assert rv.m.Keys == m.Keys + {k};
reveal rv.calidObjects();
assert rv.calidObjects();
reveal calidObjects();
assert calidObjects();
reveal calidMap();
assert calidMap();
assert rv.m.Keys == rv.ks;
assert k.owners() <= ks;
assert forall x <- m.Keys :: x.AMFO <= ks by {
assert forall x <- m.Keys, oo <- x.AMFO :: oo in m.Keys;
}
assert k.owners() <= ks;
// assert forall x <- m.Keys+{k} :: x.owner() <= ks;
assert forall x <- m.Keys+{k} :: x.AMFO <= ks+{k};
assert (ks+{k}) == m.Keys+{k} == rv.ks == rv.m.Keys;
assert forall x <- rv.m.Keys :: x.AMFO <= rv.m.Keys;
assert forall x <- rv.m.Keys, oo <- x.AMFO :: oo in rv.m.Keys;
assert (forall x <- rv.m.Keys :: x.region.Heap? == rv.m[x].region.Heap?);
assert (forall x <- rv.m.Keys | x.region.Heap? :: x.region.owner in x.AMFO);
assert (forall x <- rv.m.Keys | x.region.Heap? :: x.region.owner in rv.m.Keys);
assert (forall x <- rv.m.Keys | x.region.Heap? :: rv.m[x.region.owner] == rv.m[x].region.owner );
// //BEGIN DUNNO ABOUT THIS
// assert (forall x <- m.Keys, oo <- x.AMFO :: m[oo] in m[x].AMFO);
// assert (forall x <- m.Keys, oo <- x.AMFO :: rv.m[oo] in rv.m[x].AMFO);
// assert rv.m[k] == v;
// assert ks == m.Keys;
// assert (k.owners() <= ks);
// assert (k.AMFO - {k}) <= ks;
// assert (forall oo <- (k.AMFO - {k}):: oo in m.Keys);
// assert (forall oo <- (k.AMFO - {k}):: m[oo] in v.AMFO);
// assert (forall oo <- (k.AMFO - {k}):: rv.m[oo] in rv.m[k].AMFO);
//
// assert (forall x <- m.Keys, xo <- x.extra :: xo in m.Keys);
// assert (forall x <- m.Keys, xo <- x.extra :: m[xo] in m[x].extra);
// assert (forall x <- m.Keys, xo <- x.extra :: xo in rv.m.Keys);
// assert (forall x <- m.Keys, xo <- x.extra :: rv.m[xo] in rv.m[x].extra);
//END DUNNO ABOUT THIS
assert rv.m.Keys == m.Keys + {k};
assert rv.m == MapKV(m,k,v);
assert (forall x <- m.Keys :: (set xo <- x.extra :: m[xo]) == m[x].extra);
assert (forall x <- m.Keys :: (set xo <- x.extra :: rv.m[xo]) == rv.m[x].extra);
assert (forall x <- rv.m.Keys :: (set xo <- x.extra :: rv.m[xo]) == rv.m[x].extra);
assert (forall xo <- k.extra :: xo in rv.m.Keys);
assert (forall xo <- k.extra :: rv.m[xo] in rv.m[k].extra);
assert (forall xo <- k.extra :: xo in rv.m.Keys);
assert (forall xo <- k.extra :: rv.m[xo] in rv.m[k].extra);
assert (forall x <- {k}, xo <- x.extra :: xo in rv.m.Keys);
assert (forall x <- {k}, xo <- x.extra :: rv.m[xo] in rv.m[x].extra);
assert mapThruMapKV(k.AMFO, this, k, v) == v.AMFO;
assert (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO); //NEW BIT
assert (forall x <- rv.m.Keys :: (set oo <- x.AMFO :: rv.m[oo]) == rv.m[x].AMFO);
assert (forall x <- rv.m.Keys, oo <- x.AMFO :: rv.m[oo] in rv.m[x].AMFO);
assert (forall x <- rv.m.Keys | x.region.Heap? :: x.extra <= x.AMFO);
assert (forall x <- rv.m.Keys | x.region.Heap? :: x.extra <= rv.m.Keys);
assert (forall x <- rv.m.Keys, xo <- x.extra :: xo in rv.m.Keys);
// assert (forall x <- rv.m.Keys, xo <- x.extra :: rv.m[xo] in rv.m[x].extra);
// assert mapThruMap(k.owners(), this) == (v.AMFO - {v});
// assert mapThruMap(k.owners(), this) == (v.owners());
// // assert mapThruMap(k.AMFO, this) == (v.AMFO);//doesn't work cos k not in this.m.Keys
// assert ((set oo <- (k.AMFO - {k}) :: m[oo]) == v.AMFO - {v});
// assert ((set oo <- (k.owners()) :: m[oo]) == v.owners());
// // assert (forall x <- {k} :: (set oo <- x.owners() :: m[oo]) == m[x].owners()); //dpoesn't work cos K NOT IN M yet
// assert (forall x <- {k} :: (set oo <- x.owners() :: m[oo]) == v.owners()); //does work tho' K NOT IN M yet
//
// assert (forall x <- m.Keys :: (set oo <- x.AMFO :: m[oo]) == m[x].AMFO);
// assert (forall x <- m.Keys :: mapThruMap(x.AMFO, this) == m[x].AMFO);
//
// assert (forall x <- m.Keys + {k}
// :: (set oo <- x.AMFO :: if (oo == k) then (v) else (m[oo]))
// == if (x == k) then (v.AMFO) else (m[x].AMFO));
//
// // assert (forall x <- m.Keys + {k} :: mapThuMap(x.AMFO, this) == if x in m.Keys then (m[x].AMFO) else (v.AMFO)); //again k not in this & mapThru needs calid
//
// assert k !in m.Keys;
// // var n := m[k:=v];
// assert k.owners() <= m.Keys;
// var n := MapKV(m,k,v);
// MapKVOK(m,k,v,n);
// assert n.Keys == m.Keys + {k};
// assert (forall x <- m.Keys :: x in n.Keys);
// assert (forall x <- (m.Keys * n.Keys) :: (m[x] == n[x]));
//
// assert (forall x <- n.Keys :: (set oo <- x.AMFO :: n[oo]) == n[x].AMFO);
//
// // assert (forall x <- m.Keys+{k} :: (set oo <- x.AMFO :: m[k:=v][oo]) == m[k:=v][x].AMFO);
// // assert (forall x <- rv.m.Keys :: mapThruMap(x.AMFO, rv) == rv.m[x].AMFO); //OOPS mapThruMap needs calid...
// assert (forall x <- rv.m.Keys :: (set oo <- x.AMFO :: rv.m[oo]) == rv.m[x].AMFO);
} //MapOK
reveal rv.calidObjects();
assert ks == m.Keys;
assert rv.ks == rv.m.Keys;
assert (inside(k,rv.o)) ==> (rv.m[k] in ns);
assert rv.m[k] == v;
assert v in ns;
assert inside(k,rv.o);
assert (forall x <- ks :: (not(inside(x,o)) ==> (m[x] == x)));
assert (forall x <- ks :: (not(inside(x,o)) ==> (rv.m[x] == x)));
assert (forall x <- {k} :: (not(inside(x,o)) ==> (rv.m[x] == x)));
assert (forall x <- ks+{k} :: (not(inside(x,o)) ==> (rv.m[x] == x)));
assert rv.ks == ks + {k};
assert rv.ks == rv.m.Keys;
assert (forall x <- rv.ks :: (not(inside(x,o)) ==> (rv.m[x] == x)));
assert (forall x <- rv.m.Keys, oo <- x.AMFO :: rv.m[oo] in rv.m[x].AMFO);
assert (forall x <- ks, oo <- x.AMFO :: m[oo] in m[x].AMFO);
reveal rv.calidMap();
reveal UniqueMapEntry();
assert AllMapEntriesAreUnique(m);
assert forall i <- m.Keys :: UniqueMapEntry(m, i);
assert k !in ks;
assert v !in vs;
assert forall i <- m.Keys :: i != k;
assert forall i <- m.Keys :: m[i] != v;
assert forall i <- m.Keys+{k} :: (rv.m[i] == v ) ==> (k == i);
assert forall i <- rv.m.Keys :: UniqueMapEntry(rv.m, i);
assert
&& AllMapEntriesAreUnique(rv.m)
&& MapOK(rv.m) // potentiall should expand this out?
&& (forall x <- rv.ks :: (not(inside(x,rv.o)) ==> (rv.m[x] == x)))
&& (forall x <- rv.ks, oo <- x.AMFO :: rv.m[oo] in rv.m[x].AMFO)
;
assert rv.calidMap();
reveal rv.calidSheep();
reveal rv.calidObjects();
assert ks == m.Keys;
assert rv.ks == rv.m.Keys;
assert inside(k, o);
reveal calidMap();
assert calidMap();
reveal calidSheep();
assert forall x <- ks :: AreWeNotMen(x, this);
assert rv.ks == rv.m.Keys == (ks+{k});
assert forall x <- ks :: x.fieldModes == m[x].fieldModes;
assert k.fieldModes == v.fieldModes;
assert forall x <- rv.ks :: x.fieldModes == rv.m[x].fieldModes;
assert calidSheep();
reveal rv.calidSheep();
//reveal UniqueMapEntry();
assert ks == m.Keys;
reveal AreWeNotMen();
reveal UniqueMapEntry();
assert forall x <- ks :: AreWeNotMen(x, this);
assert forall x <- {k} :: AreWeNotMen(x, rv);
assert forall x <- rv.m.Keys :: AreWeNotMen(x, rv);
assert rv.calidSheep();
reveal rv.calid(); assert rv.calid();
rv
} //END putInside
//
//
// lemma OutsidfeValuesAreUniqueDuh()
// requires calid()
// ensures forall k <- ks ::
// {
// reveal calid();
// )
//
opaque function {:isolate_assertions} putOutside(k : Object) : (r : Map)
//put k -> k into map, k oustide o
reads oHeap`fields, oHeap`fieldModes
reads ns`fields, ns`fieldModes
requires calid()
requires k !in ks
requires k !in vs
requires k !in m.Keys
requires k !in m.Values
requires k in oHeap
requires COK(k, oHeap)
requires k.owners() <= ks
requires not(inside(k, o))
requires
&& k !in m.Keys && k !in m.Values
&& COK(k,oHeap)
&& k.Ready()
&& k.AllOwnersAreWithinThisHeap(ks)
&& (forall oo <- k.AMFO - {k}:: oo in m.Keys)
// && (k.region.Heap? ==> m[k].region.Heap?) WHATR THE FUCK k at in the map!
&& (k.region.Heap? ==> k.region.owner in k.AMFO)
&& (k.region.Heap? ==> k.region.owner in m.Keys)
// && (k.region.Heap? ==> m[k.region.owner] == m[k].region.owner )
// && (forall oo <- k.AMFO :: m[oo] in m[k].AMFO)
&& (k.region.Heap? ==> k.extra <= k.AMFO)
&& (forall xo <- k.extra :: xo in m.Keys)
// && (forall xo <- k.extra :: m[xo] in m[k].extra)
requires forall kx <- k.extra :: kx in m.Keys
requires forall kx <- k.extra :: m[kx] == kx
ensures r == Map(m[k:=k], ks+{k}, vs+{k}, o, oHeap, ns)
ensures k in r.ks && r.m[k] == k
ensures k in r.m.Keys
ensures k in r.m.Values
ensures MapOK(r.m)
ensures weirdo() && (r.m == MapKV(this.m,k,k))
ensures mapLEQ(m, r.m)
ensures r.calid()
ensures r.from(this)
{
assert //the below should be a predicate (from MapKV)
&& k !in m.Keys
&& k !in m.Values
//&& COK(k,m.Keys)
&& (forall oo <- k.AMFO - {k} :: oo in m.Keys)
//&& (k.region.Heap? ==> m[k].region.Heap?)
&& (k.region.Heap? ==> k.region.owner in k.AMFO)
&& (k.region.Heap? ==> k.region.owner in m.Keys)
//&& (k.region.Heap? ==> m[k.region.owner] == m[k].region.owner )
//&& (forall oo <- k.AMFO :: m[oo] in m[k].AMFO)
&& (k.region.Heap? ==> k.extra <= k.AMFO)
&& (forall xo <- k.extra :: xo in m.Keys)
//&& (forall xo <- k.extra :: m[xo] in m[k].extra)
;
reveal calid();
assert calid();
reveal calidObjects();
assert calidObjects();
reveal calidOK();
assert calidOK();
assert ks == m.Keys;
assert calidMap();
reveal calidMap();
assert calidSheep();
reveal calidSheep();
assert MapOK(m);
assert CallOK(oHeap);
assert AllMapEntriesAreUnique(m);