-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOwnership.dfy
215 lines (165 loc) · 5.72 KB
/
Ownership.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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// Dave clark ownerhsip sketch.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
function owners(o : Object) : set<Object>
//all o's owners except o itself
{ o.owners() } //should this be a function on objects? - 'tis now
///inside or equal to
predicate inside(part : Object, whole : Object) : (rv : bool)
// reads part, whole
{
// || whole.region.World?
|| part == whole
|| whole in part.AMFO
}
predicate outside(part : Object, whole : Object) : (rv : bool)
{ not(inside(part,whole)) }
///inside BUT NOT equal to
predicate strictlyInside(part : Object, whole : Object) : (rv : bool)
// reads part, whole
{
// || whole.region.World?
&& part != whole
&& whole in part.AMFO
}
lemma InsideIsHeap(part : Object, whole : Object)
requires part.Ready()
requires inside(part, whole)
requires part != whole
ensures part.region.Heap?
{
//////reveal part.Ready();
}
///kjx 1.16 am Mon 27 May
///this also says: make world and owner, yesm bvut have ONLY ONE suchobject
///put WORLD in every object's ownershiplist (AMFO alongwith itself)
///this this is simply t.owner in f.AMFO
///WORLD could be an object
lemma {:NOTonly} PointingLemma(f : Object, t : Object)
requires || t.region.World?
|| (&& t.region.Heap?
&& t.region.owner in (f.AMFO + {f}))
ensures refOK(f,t)
{}
///OUTGOING requires something like
///if T is outside f (or outside F.owner)???
///the T must be on f's putoing list.
///needs to be consistent up the hierarcy
predicate refOK(f : Object, t : Object) : (rv : bool)
// requires ownersOK(f,os) //isthere an AMFO verison of this? //this is snow the AMFO version
// requires ownersOK(t,os)
// reads f, t//, t`region
// reads if (t.region.Heap?) then {t.region.owner} else {}
{ t.region.World? || (t.region.Heap? && inside(f,t.region.owner))
}
lemma WorldCanFuckItself(f : Object, t : Object)
requires f.region.World?
requires refOK(f,t)
{
if (t.region.World?) { assert refOK(f,t); return;}
if (t.region.Heap? && t.region.owner == f) { assert refOK(f,t); return;}
}
//pretty nice version...
lemma {:Mon18Dec} {:timeLimit 30} {:vcs_split_on_every_assert} transitiveInside(a : Object, b : Object, c : Object)
// requires a != b
// requires b != c
// requires c != a
//requires a.Valid() && b.Valid() && c.Valid()
//requires forall o <- {a, b, c} :: o.region.Heap?
requires a.Ready() && b.Ready() && c.Ready()
requires inside(a,b)
requires inside(b,c)
ensures inside(a,c)
{
//////reveal Object.Ready();
}
//////////////////////////////////////////////////////////////////////////////
/// ownership test lemmas / ownershiop accessors...
//////////////////////////////////////////////////////////////////////////////
//this one is kind of odd, really...
lemma ownerNOTInside(a : Object, b : Object, c : Object)
// requires a != b
// requires b != c
// requires c != a
requires a.Ready() && b.Ready() && c.Ready()
requires a.Valid() && b.Valid() && c.Valid()
//requires forall o <- {a, b, c} :: o.region.Heap?
requires a.region.Heap? && a.region.owner == b
// requires a.region.Heap? && (b in a.AMFO) //b is an ownwer of a?
requires c !in a.extra
//requires c !in a.AMFO
requires not(inside(b,c))
requires not(inside(c,b))
ensures not(inside(a,c))
{}
lemma insideMyDirectOwner(a : Object)
requires a.Ready() && a.Valid()
requires a.region.Heap?
ensures inside(a,a.region.owner)
{}
//a truncated eversiversion of transitiveinside
//that's sticking around for auld lang syne?
//a is inside some object c
//a != c
//b is a's direct owner
//b != c
//b is insidde c
lemma {:isolate_assertions} insideSomeIndirectOwner(a : Object, b : Object, c : Object)
requires a.Ready() && a.Valid() //not the rest?
requires a.region.Heap? && b.region.Heap?
requires a != b && a != c && b != c //not sure we need all of these...
requires inside(a,c)
requires b == a.region.owner
requires c !in a.AMFO
ensures inside(b,c)
{
if (not(inside(b,c))) //proof by contradiction...
{
assert not( b.AMFO >= c.AMFO ); //not entirely sure about all this but...
assert c !in b.AMFO;
assert a.AMFO == b.AMFO + a.extra + {a};
assert c !in a.AMFO;
assert not( a.AMFO >= c.AMFO );
assert not(inside(a,c));
assert false;
}
assert inside(b,c);
}
//Hmm is this enough.insideToAMFO
//Yes this verifies!!!
function ownersBetween(part : Object, whole : Object) : (rv : set<Object>)
requires part.Ready()
requires whole.Ready()
requires inside(part,whole)
reads part.ValidReadSet() + whole.ValidReadSet()
ensures inside(part, whole)
ensures forall r <- rv :: inside(part, r)
ensures forall r <- rv :: inside(r, whole)
{
set o <- part.AMFO | inside(o,whole)
}
lemma ownershipIsMonotonic(a : Object, b : Object, c : set<Object>)
requires a != b //oops!`
requires a in c
requires b in c
requires COK(a,c)
requires COK(b,c)
requires CallOK(c)
// ensures (a in b.AMFO) ==> (b !in a.AMFO)
requires a in b.AMFO
ensures b !in a.AMFO
{
reveal COK(), CallOK();
assert COK(a,c);
assert COK(b,c);
assert CallOK(c);
assert forall o <- a.AMFO :: (o != a) ==> (a.AMFO > o.AMFO);
assert forall o <- b.AMFO :: (o != b) ==> (b.AMFO > o.AMFO);
assert a in b.AMFO;
assert b !in a.AMFO;
}