-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.dfy
1102 lines (831 loc) · 33.8 KB
/
Object.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
datatype Region = World // region of immutable objects
| Heap(owner : Object) // objects allocated in heap region
datatype Mode =
| Rep // owned by me
| Peer // owned by my owner
//For all the Owner & Read "Modes" sholdn't the owner always be "self" i.e; the object containing the reernce.
| Owned(perm : Perm) //unrestricted, Rust-style owning reference - with no borrows!
| Loaned(perm : Perm) //owning reference, but currently there are "borrowed" references to it
| Borrow(perm: Perm, owner: Region, from : Object, name : string) //borrowed reference, borrowe from that object!
//when one does a "stack-pop-return" into the obejct that this was borrowed from
//then the Mode of the owning refernece goes from Loaned -> Owned
| Evil //type dyanmic. So I don't hace to do the full checks right now --- kjx 7 May 2024
datatype Perm = Read | Write | Local ///or should these be object kinds???> ARGH!!
/// an earlier deprecated design!
// | Own(perm : Region) //unrestricted, Rust-style owning reference?
// | Read(owner : Region) //Rust stule ownering Readonly reference?
// //IF we have move semantics, could move here from Own?
// | ReadOwn(owner : Region) // I am the owner, but my contents are read-borrowed.
// | MutOwn(owner : Region) // I am the owner, but my contents are mut-borrowed.
// | LocOwn(owner : Region) // I am the owner, but my contents are loc-borrowed.
// | ReadRef(owner : Region) //
predicate AssignmentCompatible(o : Object, t : Mode, v : Object)
//can object v be assigned to a field of Mode t within object o?
{
match t
case Evil => true
case Rep | Owned(_) | Loaned(_) => v.region.Heap? && v.region.owner == o
case Peer => v.region == o.region
// case Borrow(p,b,n,f) => v.region == b
case Borrow(p,b,n,f) => refOK(o,v)
}
lemma EVILisCompatibleWithAnything(o : Object, v : Object)
ensures AssignmentCompatible(o, Evil, v)
{}
//////////////////////////////////////////////////////////////////////////////
// OBJECTS
//
//I know it's perverse, but titlecase "Object" and "Class" aren't reserved in dafny
//
//note that null / undefined fields can be declared in objects
//but may not necessarily be in the Object's fields.
class Object {
var nick : string //nickname
const region : Region//actual "dynamic" region owner of this object
//it's changed to a var now so lots of comoplaints.
//fuck should I change it back? or not? - no point in bheing VAR while AMFO is CONST!
var fields : map<string,Object>//field values. uninit fields have no entries
var fieldModes : map<string,Mode>//Mode of each field name - note, static! - would be statically known by any methods
//probably also has to go to var to get to typestate. GRRR.
const AMFO : set<Object> //All MY FUCKING Owners (aka All My Flat Owners:-)
const extra : set<Object> //additional owners e.g. for stack frames inside objects
lemma {:onlyNUKE} triceratops(aa : set<Object>, bb : set<Object>, cc : set<Object>)
ensures (aa + bb + cc) == ((aa + bb) + cc) == (aa + (bb + cc))
{}
lemma {:onlyNUKE} cordelia()
requires fields == map[]
ensures AllFieldsAreDeclared()
ensures AllFieldsContentsConsistentWithTheirDeclaration()
{}
lemma {:onlyNUKE} regan(xx : set<Object>, yy : set<Object>)
requires AllTheseOwnersAreFlatOK(xx,xx+yy)
ensures flattenAMFOs(xx) <= yy + xx
{
reveal AllTheseOwnersAreFlatOK();
assert AllTheseOwnersAreFlatOK(xx,xx+yy);
}
lemma {:onlyNUKE} gonerill(xx : set<Object>, yy : set<Object>)
ensures AllTheseOwnersAreFlatOK(xx,xx+yy) == ( flattenAMFOs(xx) <= yy + xx )
{
reveal AllTheseOwnersAreFlatOK();
assert AllTheseOwnersAreFlatOK(xx,xx+yy) == ( flattenAMFOs(xx) <= yy + xx );
}
//:onlyGRUNTS}
constructor {:isolate_assertions} cake(ks : map<string,Mode>, oo : Object, context : set<Object>, name : string, xtra : set<Object> := {} )
requires COK(oo, context)
requires CallOK(context)
requires CallOK(xtra, context)
requires ExtraIsExtra(xtra, context)
requires AllTheseOwnersAreFlatOK(oo.AMFO)
requires AllTheseOwnersAreFlatOK(xtra, oo.AMFO + xtra)
//requires flattenAMFOs(xtra) <= oo.AMFO + xtra ///hmmmmAllTheseOwnersAreFlatOK
//requires CallOK({oo}+oo.AMFO, context)
// extraOK requires xtra == {} //extra not yet cloned
ensures region == Heap(oo)
ensures fieldModes == ks
ensures fields == map[]
ensures extra == xtra
ensures AMFO == oo.AMFO + {this} + xtra
ensures this in AMFO
ensures this !in extra
ensures nick == name
ensures (forall o <- AMFO :: inside(this, o))
ensures COK(this, context+{this})
//ensures CallOK({this} + {oo}+oo.AMFO, {this} + context)
ensures unchanged( context )
ensures fresh(this)
modifies {}
{
region := Heap(oo);
fieldModes := ks;
fields := map[];
AMFO := oo.AMFO + xtra + {this};
nick := name;
extra := xtra;
new;
assert fieldModes == ks;
assert fields == map[];
assert nick == name;
assert extra == xtra;
assert COK(oo, context);
assert CallOK(context);
COKAMFO(oo, context);
assert (this in context+{this}) by { reveal COK(), CallOK(); }
assert (xtra <= context) by { reveal COK(), CallOK(); }
assert (AMFO <= context+{this}) by { reveal COK(), CallOK(); }
assert CallOK(oo.AMFO, context);
assert (oo.AMFO) <= context by { reveal CallOK(), COK(); }
CallOKWiderContext(oo.AMFO,context,{this});
assert CallOK(oo.AMFO, {this}+context) by { assert {this}+context == context+{this}; }
assert COK(this, {this}+context) by
{
reveal COK();
assert (this in ({this}+context));
assert (this.AMFO <= ({this}+context));
RVfromCOK(oo,context);
RVfromCallOK(extra, context);
assert (forall x <- extra :: x.Ready());
assert (forall x <- extra :: this !in x.AMFO);
assert (forall x <- extra :: AMFO > x.AMFO) by {
reveal COK();
reveal AllTheseOwnersAreFlatOK();
assert AllTheseOwnersAreFlatOK(extra, oo.AMFO+extra);
}
assert CallOK(extra,context);
assert AMFO == oo.AMFO + {this} + xtra;
assert ExtraIsExtra(extra,context);
assert (forall x <- extra :: x in x.AMFO);
assert (forall x <- extra, xo <- x.AMFO :: xo in x.AMFO);
assert (forall x <- {region.owner}, xo <- x.AMFO :: xo in x.AMFO);
assert flattenAMFOs(extra) <= oo.AMFO + extra; ///hmmmm
assert flattenAMFOs({oo} + extra) <= oo.AMFO + extra;
assert AMFO == oo.AMFO + extra + {this};
assert this !in oo.AMFO;
assert this !in extra;
assert (forall a <- oo.AMFO :: a.Ready());
assert (forall a <- oo.AMFO :: AMFO > a.AMFO);
// assert (forall a <- AMFO :: AMFO > a.AMFO);
assert region.owner.Ready();
assert (forall owner <- (AMFO - {this}) :: owner.Ready());
assert (forall owner <- (AMFO - {this}) :: AMFO > owner.AMFO);
assert (this.Ready());
assert (this.Valid());
assert (this.AllOutgoingReferencesAreOwnership(({this}+context))) ;
assert (this.AllOutgoingReferencesWithinThisHeap(({this}+context)));
assert (this.AllOwnersAreWithinThisHeap(({this}+context)));
reveal AllTheseOwnersAreFlatOK();
assert AllTheseOwnersAreFlatOK(extra, oo.AMFO+extra);
assert AllTheseOwnersAreFlatOK(AMFO - {this});
assert AllTheseOwnersAreFlatOK(region.owner.AMFO);
assert (AllTheseOwnersAreFlatOK(extra,(region.owner.AMFO+extra)));
assert COK(this, {this}+context);
}
assert COKOK: COK(this, context+{this})
by { assert {this}+context == context+{this}; }
CallOKfromCOK(this, {this}+context);
assert CallOK({this}, {this}+context) ;
CallOKWiderFocus({this}, oo.AMFO, {this} + context);
assert CallOK({this} + (oo.AMFO), {this} + context);
//assert CallOK(xtra, context);
assert CallOK({this} + oo.AMFO, {this} + context);
assert COK(this, context+{this}) by { reveal COKOK; }
print "Object.cake() just constructed ", fmtobj(this), "\n";
}
constructor {:onlyFROZZ} frozen(ks : map<string,Mode>)
ensures region == World
ensures fieldModes == ks
ensures fields == map[] //object fields starts uninitialised
ensures AMFO == {this}
ensures this in AMFO
ensures this !in extra
ensures Ready()
ensures OwnersValid()
ensures Valid()
ensures TRUMP()
ensures nick is string
ensures MOGO()
ensures fresh(this)
ensures extra == {}
modifies {}
{ //////reveal Ready(); //////reveal TRUMP(); //////reveal MAGA(); //////reveal MOGO();
region := World;
fieldModes := ks;
fields := map[];
AMFO := {this};
nick := "";
extra := {};
new;
assert extra == {};
assert Ready();
assert AMFO <= AMFO;
assert AllOwnersAreWithinThisHeap(AMFO);
assert fields == map[];
assert AllOutgoingReferencesAreOwnership(AMFO);
assert AllOutgoingReferencesWithinThisHeap(AMFO);
assert OwnersValid();
assert Valid();
assert TRUMP();
assert MOGO();
}
constructor {:onlyFROZZ} frozen2(ks : map<string,Mode>, oHeap : set <Object>)
ensures region == World
ensures fieldModes == ks
ensures fields == map[] //object fields starts uninitialised
ensures AMFO == {this}
ensures this in AMFO
ensures this !in extra
ensures Ready()
ensures OwnersValid()
ensures Valid()
ensures TRUMP()
ensures nick is string
ensures MOGO()
ensures unchanged(oHeap)
requires CallOK(oHeap)
ensures CallOK(oHeap)
ensures COK(this,oHeap+{this})
ensures fresh(this)
ensures extra == {}
modifies {}
{ //////reveal Ready(); //////reveal TRUMP(); //////reveal MAGA(); //////reveal MOGO();
region := World;
fieldModes := ks;
fields := map[];
AMFO := {this};
nick := "";
extra := {};
new;
assert extra == {}; assert Ready();
assert fields == map[];
assert OwnersValid();
assert Valid();
assert TRUMP();
assert MOGO();
var context := (oHeap+{this});
assert this in context;
assert AMFO <= context;
assert forall oo <- AMFO :: oo.Ready();
assert (Ready() && Valid());
assert AllOutgoingReferencesAreOwnership(context);
assert AllOutgoingReferencesWithinThisHeap(context);
assert AllOwnersAreWithinThisHeap(context);
reveal AllTheseOwnersAreFlatOK();
assert AllTheseOwnersAreFlatOK(extra);
assert AllTheseOwnersAreFlatOK(AMFO - {this});
reveal COK();
assert COK(this,context);
}
/*opaque*/ predicate {:onlyNUKE} Ready()
// ready means all the owenrs are (at least) ready...
// I had to inline the defition --- see "//Ready()inlined"
// WHO the fuck knows WHY?
// update this, update that too.
//it's important: this has *no* readsclausew
decreases AMFO
{
&& (this !in extra)
&& (region.World? || region.Heap?)
&& (region.World? ==> (AMFO == {this}))
&& (region.World? ==> (extra == {}))
&& (region.Heap? ==> (AMFO == region.owner.AMFO + extra + {this}))
&& (region.Heap? ==> (AMFO > region.owner.AMFO))
&& (region.Heap? ==> region.owner.Ready())
&& (region.Heap? ==> (forall owner <- region.owner.AMFO :: AMFO > owner.AMFO))
&& (region.Heap? ==> (forall owner <- region.owner.AMFO :: owner.Ready()))
&& (forall owner <- (AMFO - {this}) :: AMFO > owner.AMFO)
&& (forall owner <- (AMFO - {this}) :: owner.Ready())
&& (forall owner <- (extra) :: AMFO > owner.AMFO) //subsumed by the above 2 lines, but...
&& (forall owner <- (extra) :: owner.Ready())
&& (flattenAMFOs(AMFO - {this}) <= AMFO)
}
function owners() : set<Object>
//all o's owners except o itself
{ AMFO - {this} }
///*opaque*/
predicate {:onlyValid} Valid()
decreases |AMFO|
// reads ValidReadSet()`fields, ValidReadSet()`fieldModes
reads this`fields, this`fieldModes
requires Ready()
//ensures Valid() ==> OwnersValid()
// reads this, this`region, AMFO, fields.Values, AMFO`fields, AMFO`region,
// (set o1 <- AMFO, o2 <- o1.fields.Values :: o2) //JESUS MARY AND JOSEPH AND THE WEE DONKEY
{
(region.World? || region.Heap?) //turn off other regions //HMMM
&&
OwnersValid()
&&
/////////KJX {:todo} REINSTATE COS WITHOUT DOESNT HELP IS EVEIL EVILEVILEVIL
AllFieldsAreDeclared()
&&
AllFieldsContentsConsistentWithTheirDeclaration()
// &&
// (forall o <- AMFO :: recInside(this, o)) //recInside needs valid, OOPS.
// // &&
// AllOutgoingReferencesAreVenice()
}
predicate AllFieldsAreDeclared()
reads this`fields, this`fieldModes
{ fields.Keys <= fieldModes.Keys }
predicate AllFieldsContentsConsistentWithTheirDeclaration()
requires AllFieldsAreDeclared()
reads this`fields, this`fieldModes
{
forall n <- fields :: AssignmentCompatible(this, fieldModes[n], fields[n])
}
predicate AllOutgoingReferencesAreOwnership(os : set<Object>)
reads this`fields//, fields.Values, os//semi-evil
requires Ready() // || TRUMP()
//requires forall n <- fields :: ownersOK(fields[n],os)
{
&& (forall n <- fields :: refOK(this, fields[n]))
}
predicate AllOutgoingReferencesWithinThisHeap(os : set<Object>)
reads this`fields //, fields.Values, this, os//semi-evil
requires Ready() // || TRUMP()
//requires forall n <- fields :: ownersOK(fields[n],os)
{
outgoing() <= os
}
lemma NoFieldsAreGoodFields(context : set<Object>)
requires fields == map[]
requires Ready()
ensures AllOutgoingReferencesAreOwnership(context)
ensures AllOutgoingReferencesWithinThisHeap(context)
{
}
predicate AllOwnersAreWithinThisHeap(os : set<Object>)
// reads this, fields.Values, this, os//semi-evil
requires Ready() //requires forall n <- fields :: ownersOK(fields[n],os)
{
owners() <= os
}
function outgoing() : set<Object> reads this`fields { fields.Values }
function fieldNames() : set<string> reads this`fields { fields.Keys } //WAS { fieldModes.Keys }
function size() : nat reads this`fields { |outgoing()| }
function ValidReadSet() : set<Object>
reads this`fields, AMFO`fields
{
{this} + fields.Values + AMFO +
(set o1 <- AMFO, o2 <- o1.fields.Values :: o2) //JESUS MARY AND JOSEPH AND THE WEE DONKEY
}
lemma ReadyGetsOwnersValid()
requires Ready()
ensures OwnersValid()
{
//////reveal Ready();
assert OwnersValid();
}
predicate {:onlyNUKE} OwnersValid() : (rv : bool) //newe version with Ready {}Mon18Dec}
decreases AMFO
//requires Ready()
{
&& (Ready())
&& (region.World? || region.Heap?)
&& (this in AMFO)
&& (region.World? ==> (AMFO == {this}))
&& (region.Heap? ==> (AMFO > {}))
&& ((region.Heap?) ==> region.owner in AMFO)
&& ((region.Heap?) ==> assert region.owner in AMFO; AMFO > region.owner.AMFO)
&& ((region.Heap?) ==> (AMFO == region.owner.AMFO + extra + {this}))
&& ((region.Heap?) ==> assert region.owner in AMFO; region.owner.Ready())
&& (forall own <- (AMFO - {this}) :: (own.AMFO < AMFO) && own.Ready())
&& (forall o <- AMFO :: inside(this, o)) // {todo could move this out}
&& (forall b <- AMFO, c <- b.AMFO :: c in AMFO && inside(b,c) && inside(this,c))
}
// predicate {:vcs_split_on_every_assert} WTFOwnersValid() : (rv : bool) //newe version with Ready {}Mon18Dec}
// decreases AMFO
// ensures rv ==> (region.World? || region.Heap?)
// ensures rv ==> (this !in AMFO)
// ensures rv ==> (region.World? ==> (AMFO == {}))
// ensures rv ==> (region.Heap? ==> (AMFO > {}))
// ensures rv ==> ((region.Heap?) ==> region.owner in AMFO)
// ensures rv ==> ((region.Heap?) ==> assert region.owner in AMFO; AMFO > region.owner.AMFO)
// // ensures rv ==> ((region.Heap?) ==> assert region.owner in AMFO; |AMFO| > |region.owner.AMFO|)
// ensures rv ==> ((region.Heap?) ==> (AMFO == region.owner.AMFO + {region.owner}))
// ensures rv ==> ((region.Heap?) ==> assert region.owner in AMFO; region.owner.Ready())
// ensures rv ==> (forall own <- (AMFO - {this}) :: (own.AMFO < AMFO) && own.Ready())
// ensures rv ==> (forall o <- AMFO :: inside(this, o)) // {todo could move this out}
// ensures rv ==> (forall b <- AMFO, c <- b.AMFO :: c in AMFO && inside(b,c) && inside(this,c))
// // ensures (forall b <- AMFO, c <- b.AMFO :: c in AMFO && recInside(b,c) && recInside(this,c)))
// {
// //////reveal Ready();
// Ready()
// }
lemma {:onlyAMFO} AMFOsisAMFOs()
requires Ready()
requires OwnersValid()
ensures forall oo <- AMFO :: oo.AMFO <= AMFO
{}
lemma {:onlyAMFO} AMFOsisAMFOs2()
requires Ready()
requires OwnersValid()
ensures forall x <- AMFO, oo <- x.AMFO :: oo.AMFO <= AMFO
{}
lemma CallMyOwnersWillWitherAway(a : Object, context : set<Object>)
requires CallOK(context)
requires (a in context) || (COK(a, context))
ensures a.AMFO <= context
ensures forall oo <- a.AMFO :: COK(oo, context)
//should we add more stuff in here, like::
// ensures forall oo <- a.AMFO :: oo.AMFO <= a.AMFO <= context
ensures a.region.Heap? ==> COK(a.region.owner,context)
ensures a.region.Heap? ==> a.region.owner in context
{
reveal CallOK();
reveal COK();
}
/*opaque*/ predicate {:onlyTRUMP} TRUMP() ///*opaque*/ Valid()
reads this`fields, this`fieldModes
// reads ValidReadSet()`fields, ValidReadSet()`fieldModes
{ Ready() && Valid() }
lemma {:onlyTRUMP} BIDEN()
requires TRUMP()
ensures Ready() && Valid()
{
//////reveal TRUMP();
}
function deTRUMP(gop : Object) : (dem : Object)
reads gop.ValidReadSet()`fields, gop.ValidReadSet()`fieldModes
requires gop.TRUMP()
ensures dem.Ready()
ensures dem.Valid()
{ gop.BIDEN(); gop }
lemma AllStandaloneMonotonic(aa : set<Object>, bb : set<Object>)
//we have MOGO(aa); SUPERMOGO(bb,aa+bb); ==> MOGO(aa+bb);
///note that there's *no* constraint saying aa !! bb
requires forall o <- (aa) :: (o.TRUMP())
requires forall o <- (aa) :: (deTRUMP(o).AllOutgoingReferencesAreOwnership(aa))
requires forall o <- (aa) :: (o.AllOutgoingReferencesWithinThisHeap(aa))
requires forall o <- (aa) :: (o.AllOwnersAreWithinThisHeap(aa))
requires forall o <- (bb) :: (o.TRUMP())
requires forall o <- (bb) :: (deTRUMP(o).AllOutgoingReferencesAreOwnership(aa+bb))
requires forall o <- (bb) :: (o.AllOutgoingReferencesWithinThisHeap(aa+bb))
requires forall o <- (bb) :: (o.AllOwnersAreWithinThisHeap(aa+bb))
ensures forall o <- (aa) :: (o.TRUMP())
ensures forall o <- (aa) :: (o.AllOutgoingReferencesAreOwnership(aa+bb))
ensures forall o <- (aa) :: (o.AllOutgoingReferencesWithinThisHeap(aa+bb))
ensures forall o <- (aa) :: (o.AllOwnersAreWithinThisHeap(aa+bb))
{
}
/*opaque*/ predicate MOGO() : (rv : bool)
reads set o1 <- (AMFO + {this}), o2 <- o1.ValidReadSet() :: o2`fields
reads (AMFO + {this})`fields
reads set o1 <- (AMFO + {this}), o2 <- o1.fields.Values :: o2`fields
reads set o1 <- (AMFO + {this}), o2 <- o1.ValidReadSet() :: o2`fieldModes
reads (AMFO + {this})`fieldModes
reads set o1 <- (AMFO + {this}), o2 <- o1.fields.Values :: o2`fieldModes
// reads set o1 <- (AMFO + {this}), o2 <- o1.ValidReadSet() :: o2
// reads (AMFO + {this}), (AMFO + {this})`fields
// reads set o1 <- (AMFO + {this}), o2 <- o1.fields.Values :: o2
// ensures SUPERMAGA( {this} + AMFO, {this} + AMFO) ///be nice, but I wannt make verythiug TRUMP?
{
//////reveal MOGO();
MAGA({this} + AMFO)
}
//all aa's individually MAGA-ishg within context
//MAGA could be rewritteninterhsmof this?
/*opaque*/ predicate {:onlyWANKER} SUPERMAGA(aa : set<Object>, context : set<Object>)
reads set o1 <- (aa+context), o2 <- o1.ValidReadSet() :: o2
reads (aa+context), (aa+context)`fields
reads set o1 <- (aa+context), o2 <- o1.fields.Values :: o2
requires forall o <- (aa) :: o.TRUMP()
requires forall o <- (context) :: o.TRUMP()
{
&& (forall o <- (aa) :: (deTRUMP(o).Ready()))
&& (forall o <- (aa) :: (o.AllOutgoingReferencesAreOwnership(context)) )
&& (forall o <- (aa) :: (o.AllOutgoingReferencesWithinThisHeap(context)))
&& (forall o <- (aa) :: (o.AllOwnersAreWithinThisHeap(context)))
}
/*opaque*/ predicate MAGA(aa : set<Object>) : (rv : bool)
// reads (set o1 <- aa, o2 <- o1.ValidReadSet() :: o2)
// reads set o1 <- aa, o2 <- o1.ValidReadSet() :: o2
// reads aa, aa`fields
// reads set o1 <- aa, o2 <- o1.fields.Values :: o2
reads (set o1 <- aa, o2 <- o1.ValidReadSet() :: o2)`fields
reads (set o1 <- aa, o2 <- o1.ValidReadSet() :: o2)`fieldModes
reads aa`fields, aa`fieldModes
reads set o1 <- aa, o2 <- o1.fields.Values :: o2`fields
reads set o1 <- aa, o2 <- o1.fields.Values :: o2`fieldModes
// ensures rv ==> SUPERMAGA(aa,aa)
{
var res :=
&& (forall o <- (aa) :: (o.TRUMP()))
&& (forall o <- (aa) :: (deTRUMP(o).AllOutgoingReferencesAreOwnership(aa)) )
&& (forall o <- (aa) :: (o.AllOutgoingReferencesWithinThisHeap(aa)))
&& (forall o <- (aa) :: (o.AllOwnersAreWithinThisHeap(aa)));
assert true;
res
}
} //end class Object
//extended validity
predicate ExtraIsExtra(xtra : set<Object>, context : set<Object>)
// why did I put all thjese READS clases im hjere - when they are unnecessary..?
// reads (set x <- xtra, xa <- x.AMFO :: xa)`fields
// reads (set x <- xtra, xa <- x.AMFO :: xa)`fieldModes
// reads xtra`fields, xtra`fieldModes
{
// && CallOK(xtra, context) ///DO I WANT THIS, O JUST "READY"""
&& (forall e <- xtra :: e in e.AMFO)
&& (forall e <- xtra :: e.AMFO <= context)
//&& (forall e <- xtra :: e.AMFO <= xtra) //is this want we want..?
///NO! it isn't. kept for now as a reminder
//I bet this can be refactored into the COK if it isn't already
}
//compare the fucking AllOwnersAreWthinThisHeap???
opaque predicate AllTheseOwnersAreFlatOK(os : set<Object>, context : set<Object> := os)
// true iff all os's AMFOS are inside os
// probalby need to do - {a} if these are for {a} or else it gets circular...?
{
// && (forall o <- os :: o in o.AMFO)
&& flattenAMFOs(os) <= context
} //IT"S NOT CLEAR OWHAT THIS SHOULD DO (or if it matters)
//&& flattenAMFOs(a.AMFO - {a}) <= a.AMFO //should it be this?
//&& flattenAMFOs(a.AMFO - {a}) <= (a.AMFO - {a}) //or should it be this instead?
//&& flattenAMFOs(a.AMFO + {a}) <= (a.AMFO + {a}) //or even this?
predicate OrigBigfoot(os : set<Object>, context : set<Object> := os)
{
&& (os <= context)
&& (forall o <- os :: o.AMFO <= context)
}
predicate Bigfoot(os : set<Object>, context : set<Object> := os) : ( r : bool )
ensures r ==> AllTheseOwnersAreFlatOK(os,context)
{
reveal AllTheseOwnersAreFlatOK();
OrigBigfoot(os,context)
}
lemma PsychoBigFoot(os : set<Object>, context : set<Object> := os, m : Map)
requires m.calid()
requires os <= m.ks
requires os <= m.m.Keys
requires context <= m.ks
requires context <= m.m.Keys
requires os <= context
requires OrigBigfoot(os,context)
ensures m.calid()
ensures os <= m.ks
ensures os <= m.m.Keys
ensures context <= m.ks
ensures context <= m.m.Keys
ensures os <= context
ensures OrigBigfoot(mapThruMap(os,m),mapThruMap(context,m))
{
assert (os <= context);
assert (forall o <- os :: o.AMFO <= context);
assert OrigBigfoot(os,context);
reveal m.calid(); assert m.calid();
reveal m.calidObjects(); assert m.calidObjects();
reveal m.calidOK(); assert m.calidOK();
reveal m.calidMap(); assert m.calidMap();
reveal m.calidSheep(), m.calidSheep2();
assert m.calidSheep();
assert MapOK(m.m);
assert (forall x <- m.m.Keys ::
(set oo <- x.AMFO :: m.m[oo]) == m.m[x].AMFO); //NEW BIT
assert os <= m.ks;
assert os <= m.m.Keys ;
assert context <= m.ks;
assert context <= m.m.Keys ;
assert os <= context;
assert OrigBigfoot(os,context);
assert (forall o <- os :: o.AMFO <= context);
assert mapThruMap(os, m) <= mapThruMap(context, m);
assert m.calid();
BothSidesNow(m.m);
MapThruMapPreservesSubsets(os, context, m);
MapThruMapPreservesAMFO(os, context, m);
forall o <- os ensures (
mapThruMap(o.AMFO, m) <= mapThruMap(context, m))
{
assert o.AMFO <= context;
MapThruMapPreservesSubsets(o.AMFO, context, m);
assert mapThruMap(o.AMFO, m) == m.m[o].AMFO;
}
forall r <- mapThruMap(os, m) ensures (
r.AMFO <= mapThruMap(context, m)) {
MapThruMapPreservesSubsets(os, context, m);
MapThruMapPreservesAMFO(os, context, m);
assert r.AMFO <= mapThruMap(context, m);
}
assert (forall o <- mapThruMap(os, m) :: o.AMFO <= mapThruMap(context, m));
assert OrigBigfoot(mapThruMap(os,m),mapThruMap(context,m));
}
lemma SPLATTO(os : set<Object>, context : set<Object> := os)
ensures OrigBigfoot(os,context) == AllTheseOwnersAreFlatOK(os,context)
{
reveal AllTheseOwnersAreFlatOK();
}
lemma MaybeOrMaybeNot(o : Object, os : set<Object>)
//does it matter of we care if "this" is in the set of AMFO's we're flattening?
//I dob't think so, as long as it's OK...?
//or rather, if os are OKJ, o.AMFO <= os, os+o are OK too...
requires o !in flattenAMFOs(os)
requires AllTheseOwnersAreFlatOK(os)
requires o.AMFO <= (os + {o})
ensures AllTheseOwnersAreFlatOK(os+{o})
{
reveal AllTheseOwnersAreFlatOK();
}
/*oopaque or not or both */
function flattenAMFOs(os : set<Object>) : (of : set<Object>)
//flattened set of os.AMFO
//earlier version required o in all objects AMFS, that's gone now
//could put it back, require os to be Ready, or remove the os+ below
//currently going with the version with fewer requirements...
//requires forall o <- os :: o in o.AMFO //not needed adding in os anyway
ensures forall o <- os :: o in of
ensures forall o <- os, oo <- o.AMFO :: oo in of
ensures os <= of
{
os + ///not needed if we keep "requires forall o <- os :: o in o.AMFO"
(set o <- os, oo <- o.AMFO :: oo)
}
//GRRRR
// lemma EitherWayIsFlat(a : Object, rrm : Map, amx : set<Object>)
// //requires rrm.calid()
// requires forall o <- a.extra, oo <- o.AMFO ::
// && o in rrm.m.Keys
// && oo in rrm.m.Keys
// && rrm.m[o] in amx
// && rrm.m[oo] in amx
// ensures AllTheseOwnersAreFlatOK(a.extra, amx)
// {
// assert flattenAMFOs(mapThruMap(a.extra,rrm)) <= amx;
// }
lemma FlatExtras(xtra : set<Object>, context : set<Object>)
requires forall o <- xtra :: o in o.AMFO
requires forall o <- xtra :: o.AMFO <= context
requires CallOK(xtra, context)
ensures CallOK(xtra, context)
ensures (forall e <- xtra :: e.AMFO <= context)
ensures xtra <= context
// ensures ExtraIsExtra(flattenAMFOs(xtra), context)
{
reveal CallOK(), COK();
assert CallOK(xtra, context);// by { reveal fuka;}
assert ExtraIsExtra(flattenAMFOs(xtra), context);
}
lemma Splurge(o : Object, context : set<Object>)
requires o.region.Heap?
requires COK(o, context)
ensures forall oo <- (o.AMFO - {o}) :: o.AMFO > oo.AMFO
ensures reveal COK(); flattenAMFOs(o.AMFO - {o}) <= o.AMFO
ensures AllTheseOwnersAreFlatOK(o.owners())
{
reveal COK();
// assert o in o.AMFO;
// assert forall oo <- (o.AMFO - {o}) :: oo in oo.AMFO;
// assert forall oo <- (o.AMFO - {o}) :: o !in oo.AMFO;
// assert forall oo <- (o.AMFO - {o}) :: o.AMFO > oo.AMFO;
// assert flattenAMFOs(o.AMFO) <= o.AMFO;
}
predicate {:vcs_split_on_every_assert}{:timeLimit 10} StandaloneObjectsAreValid(os : set<Object>) //do we know if "os" is "closed"?
// reads set o <- os, rd <- ({o} + o.fields.Values) :: rd
// requires OutgoingReferencesAreInTheseObjects(os) ///why is this needed now?
//requires os <= objects
//reads this, objects
requires forall o <- os :: o.Ready() && o.Valid()
reads os, os`fields//, os`region //os`AMFO,
reads (set o1 <- os, o2 <- o1.ValidReadSet() :: o2)
// //reads set o <- os :: o`AMFO
// reads set o <- os :: o
// reads set o <- os :: o`fields
// reads (set o1 <- os, o2 <- o1.ValidReadSet() :: o2)
//reads objects`fields, objects`region // objects`AMFO,
{
forall o <- os :: StandaloneObjectIsValid(o,os)
}
// todo: rename with a "withinthisheap" or something?
predicate {:todo "really todo - add in other cases"} StandaloneObjectIsValid(o : Object, os : set<Object>)
reads o`fields, o`fieldModes
reads os`fields, os`fieldModes
// reads os, o, o.ValidReadSet()
// reads (set o1 <- os, o2 <- o1.ValidReadSet() :: o2)
requires o.Ready()
requires forall o <- os :: o.Ready() && o.Valid()
{
&& (o.Valid())
&& (o.AllOutgoingReferencesAreOwnership(os))
// && (o.AllOutgoingReferencesWithinThisHeap(os))
// && (o.AllOwnersAreWithinThisHeap(os))
}
predicate OutgoingReferencesAreInTheseObjects(os : set<Object>)
reads os
//note that this is within *this objectset
//see also OutgoingReferencesAreInThisHeap
{
(forall o <- os :: o.outgoing() <= os)
}
predicate OutgoingHeapReferencesAreInTheseObjects(os : set<Object>)
reads os
{
// OutgoingReferencesAreInTheseObjects(os)
(forall f <- os, t <- f.outgoing()
| f.region.Heap? && t.region.Heap? :: t in os )
}
predicate OutgoingReferencesFromTheseObjectsAreToTheseObjects(fs : set<Object>, ts : set<Object>)
reads fs
{
(forall f <- fs :: f.outgoing() <= ts)
}
predicate OutgoingHeapReferencesFromTheseObjectsAreToTheseObjects(fs : set<Object>, ts : set<Object>)
reads fs
{
// OutgoingReferencesFromTheseObjectsAreToTheseObjects(fs,ts)
(forall f <- fs, t <- f.outgoing()
| f.region.Heap? && t.region.Heap? :: t in ts )
}
lemma NoIncomingReferencesMeansNoOutgoingReferences(o : Object, os : set<Object>)
requires forall o <- os :: o.Ready() && o.Valid() ///grrr..
requires incomingEdges(o, edges(os)) == {}
requires OutgoingReferencesFromTheseObjectsAreToTheseObjects(os, os+{o})///HMM
ensures forall e <- edges(os) :: e.t != o
ensures forall x <- os :: (outgoingEdges(x, edges(os)) <= edges(os))
ensures forall x <- os, e <- outgoingEdges(x, edges(os)) :: e.t != o
ensures forall x <- os :: o !in x.outgoing()
ensures OutgoingReferencesAreInTheseObjects(os)
{
var es := edges(os);
var ie := incomingEdges(o, edges(os));
assert ie == {};
assert (set e <- es | e.t == o) == {};
//attempt at contradiction
if (exists e <- es :: e.t == o)
{
var e :| e in es && e.t == o;
assert e in es;
assert e in ie;
assert ie != {};
assert false;
}
assert not(exists e <- es :: e.t == o);
assert forall e <- es :: e.t != o;
edgesWork(os,es);
edgesWorks2(os,es);
assert ObjectsToEdges(os,es);
assert forall x <- os :: o !in x.outgoing();
}
lemma RefCountDistributesOverDisjointEdges(oo : set<Object>, aa : set<Edge>, bb : set<Edge>)
requires aa !! bb
ensures
forall i <- oo ::
refCountEdges(i, aa + bb) == refCountEdges(i, aa) + refCountEdges(i, bb)
ensures
forall i <- oo ::
incomingEdges(i, aa + bb) == incomingEdges(i, aa) + incomingEdges(i, bb)
{
//calc == {
assert forall i <- oo ::
(set e <- aa | e.t == i) + (set e <- bb | e.t == i)
== (set e <- (aa+bb) | e.t == i);
assert forall i <- oo ::
incomingEdges(i,aa) + incomingEdges(i,bb)
== incomingEdges(i,aa+bb);
assert forall i <- oo ::
refCountEdges(i,aa) + refCountEdges(i,bb)
== refCountEdges(i,aa+bb);