-
Notifications
You must be signed in to change notification settings - Fork 0
/
datafrog_opt.thm
683 lines (606 loc) · 17 KB
/
datafrog_opt.thm
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
Kind origin type.
Kind loan type.
Kind point type.
/* input */
Type origin_live_on_entry origin -> point -> prop.
Type loan_issued_at origin -> loan -> point -> prop.
Type cfg_edge point -> point -> prop.
Type loan_invalidated_at loan -> point -> prop.
Type not_loan_killed_at loan -> point -> prop.
Type subset_base origin -> origin -> point -> prop.
/* At any point, the origin must either be live or dead */
Theorem OriginLiveAxiom:
forall Origin,
forall Point,
(origin_live_on_entry Origin Point ) \/ ( origin_live_on_entry Origin Point -> false).
skip.
Define dead_borrow_region_can_reach_root: origin -> point -> loan -> prop ,
dead_borrow_region_can_reach_dead: origin -> point -> loan -> prop,
dying_region_requires: origin -> point -> point -> loan -> prop ,
live_to_dying_regions: origin -> origin -> point -> point -> prop ,
dying_can_reach_origins: origin -> point -> point -> prop ,
dying_can_reach: origin -> origin -> point -> point -> prop,
dying_can_reach_live: origin -> origin -> point -> point -> prop ,
datafrog_opt_subset: origin -> origin -> point -> prop,
datafrog_opt_origin_contains_loan_on_entry: origin -> loan -> point -> prop,
datafrog_opt_loan_live_at: loan -> point -> prop,
datafrog_opt_errors: loan -> point -> prop by
dead_borrow_region_can_reach_root Origin Point Loan :=
loan_issued_at Origin Loan Point /\
(origin_live_on_entry Origin Point -> false) ;
dead_borrow_region_can_reach_dead Origin Point Loan :=
dead_borrow_region_can_reach_root Origin Point Loan;
dead_borrow_region_can_reach_dead Origin2 Point Loan :=
exists Origin1,
dead_borrow_region_can_reach_dead Origin1 Point Loan /\
datafrog_opt_subset Origin1 Origin2 Point /\
( origin_live_on_entry Origin2 Point -> false );
dying_region_requires Origin Point1 Point2 Loan :=
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point1 /\
not_loan_killed_at Loan Point1 /\
cfg_edge Point1 Point2 /\
(origin_live_on_entry Origin Point2 -> false);
live_to_dying_regions Origin1 Origin2 Point1 Point2 :=
datafrog_opt_subset Origin1 Origin2 Point1 /\
cfg_edge Point1 Point2 /\
origin_live_on_entry Origin1 Point2 /\
(origin_live_on_entry Origin2 Point2 -> false ) ;
dying_can_reach_origins Origin2 Point1 Point2 :=
exists Origin1,
live_to_dying_regions Origin1 Origin2 Point1 Point2 ;
dying_can_reach_origins Origin Point1 Point2 :=
exists Loan,
dying_region_requires Origin Point1 Point2 Loan ;
dying_can_reach Origin1 Origin2 Point1 Point2 :=
dying_can_reach_origins Origin1 Point1 Point2 /\
datafrog_opt_subset Origin1 Origin2 Point1 ;
dying_can_reach Origin1 Origin3 Point1 Point2 :=
exists Origin2,
dying_can_reach Origin1 Origin2 Point1 Point2 /\
( origin_live_on_entry Origin2 Point2 -> false ) /\
datafrog_opt_subset Origin2 Origin3 Point1 ;
dying_can_reach_live Origin1 Origin2 Point1 Point2 :=
dying_can_reach Origin1 Origin2 Point1 Point2 /\
origin_live_on_entry Origin2 Point2 ;
datafrog_opt_subset Origin1 Origin2 Point :=
subset_base Origin1 Origin2 Point ;
datafrog_opt_subset Origin1 Origin2 Point2 :=
exists Point1,
datafrog_opt_subset Origin1 Origin2 Point1 /\
cfg_edge Point1 Point2 /\
origin_live_on_entry Origin1 Point2 /\
origin_live_on_entry Origin2 Point2 ;
datafrog_opt_subset Origin1 Origin3 Point2 :=
exists Point1,
exists Origin2,
live_to_dying_regions Origin1 Origin2 Point1 Point2 /\
dying_can_reach_live Origin2 Origin3 Point1 Point2 ;
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point :=
loan_issued_at Origin Loan Point ;
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point2 :=
exists Point1,
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point1 /\
not_loan_killed_at Loan Point1 /\
cfg_edge Point1 Point2 /\
origin_live_on_entry Origin Point2 ;
datafrog_opt_origin_contains_loan_on_entry Origin2 Loan Point2 :=
exists Point1,
exists Origin1,
dying_region_requires Origin1 Point1 Point2 Loan /\
dying_can_reach_live Origin1 Origin2 Point1 Point2 ;
datafrog_opt_loan_live_at Loan Point :=
exists Origin,
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point /\
origin_live_on_entry Origin Point ;
datafrog_opt_loan_live_at Loan Point :=
exists Origin1,
exists Origin2,
dead_borrow_region_can_reach_dead Origin1 Point Loan /\
datafrog_opt_subset Origin1 Origin2 Point /\
origin_live_on_entry Origin2 Point ;
datafrog_opt_errors Loan Point :=
loan_invalidated_at Loan Point /\
datafrog_opt_loan_live_at Loan Point .
Define naive_subset: origin -> origin -> point -> prop by
naive_subset Origin1 Origin2 Point :=
subset_base Origin1 Origin2 Point ;
naive_subset Origin1 Origin2 Point2 :=
exists Point1,
naive_subset Origin1 Origin2 Point1 /\
cfg_edge Point1 Point2 /\
origin_live_on_entry Origin1 Point2 /\
origin_live_on_entry Origin2 Point2 ;
naive_subset Origin1 Origin3 Point :=
exists Origin2,
naive_subset Origin1 Origin2 Point /\
naive_subset Origin2 Origin3 Point .
Define naive_origin_contains_loan_on_entry: origin -> loan -> point -> prop by
naive_origin_contains_loan_on_entry Origin Loan Point :=
loan_issued_at Origin Loan Point ;
/* naive_origin_contains_loan_on_entry Origin Loan Point := */
/* cfg_node Point */
/* placeholder_Loan Origin Loan ; */
naive_origin_contains_loan_on_entry Origin2 Loan Point :=
exists Origin1,
naive_origin_contains_loan_on_entry Origin1 Loan Point /\
naive_subset Origin1 Origin2 Point ;
naive_origin_contains_loan_on_entry Origin Loan Point2 :=
exists Point1,
naive_origin_contains_loan_on_entry Origin Loan Point1 /\
not_loan_killed_at Loan Point1 /\
cfg_edge Point1 Point2 /\
origin_live_on_entry Origin Point2 .
Define naive_loan_live_at: loan -> point -> prop by
naive_loan_live_at Loan Point :=
exists Origin,
naive_origin_contains_loan_on_entry Origin Loan Point /\
origin_live_on_entry Origin Point .
Define naive_errors: loan -> point -> prop by
naive_errors Loan Point :=
loan_invalidated_at Loan Point /\
naive_loan_live_at Loan Point .
Theorem Lemma24:
(
forall Point,
forall Origin1,
forall Origin9,
datafrog_opt_subset Origin1 Origin9 Point ->
naive_subset Origin1 Origin9 Point
) /\ (
forall Point1,
forall Point2,
forall Origin1,
forall Origin9,
dying_can_reach Origin1 Origin9 Point1 Point2 ->
naive_subset Origin1 Origin9 Point1
).
induction on 1 1.
split.
intros.
case H1.
search.
apply IH to H2.
search.
case H2.
case H3.
apply IH to H4.
apply IH1 to H8.
search.
intros.
case H1.
apply IH to H3.
search.
apply IH1 to H2.
apply IH to H4.
search.
Theorem Lemma26:
forall Origin,
forall Loan,
forall Point,
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point ->
naive_origin_contains_loan_on_entry Origin Loan Point .
induction on 1.
intros.
case H1.
search.
apply IH to H2.
search.
case H2.
apply IH to H4.
case H3.
case Lemma24.
apply H12 to H9.
search.
Theorem Lemma51:
forall Origin,
forall Loan,
forall Point,
dead_borrow_region_can_reach_dead Origin Point Loan ->
naive_origin_contains_loan_on_entry Origin Loan Point.
induction on 1.
intros.
case H1.
case H2.
search.
apply IH to H2.
case Lemma24.
apply H6 to H3.
search.
Theorem DatafrogOpt2Naive:
forall Loan,
forall Point,
datafrog_opt_errors Loan Point ->
naive_errors Loan Point.
intros.
case H1.
case H3.
apply Lemma26 to H4.
search.
apply Lemma51 to H4.
case Lemma24.
apply H8 to H5.
search.
Define my_subset: origin -> origin -> point -> prop,
my_origin_contains_loan_on_entry: origin -> loan -> point -> prop by
my_subset Origin1 Origin2 Point :=
datafrog_opt_subset Origin1 Origin2 Point ;
my_subset Origin1 Origin3 Point :=
exists Origin2,
datafrog_opt_subset Origin1 Origin2 Point /\
my_subset Origin2 Origin3 Point ;
my_origin_contains_loan_on_entry Origin Loan Point :=
datafrog_opt_origin_contains_loan_on_entry Origin Loan Point ;
/* my_origin_contains_loan_on_entry Origin Loan Point := */
/* cfg_node Point */
/* placeholder_Loan Origin Loan ; */
my_origin_contains_loan_on_entry Origin2 Loan Point :=
exists Origin1,
my_origin_contains_loan_on_entry Origin1 Loan Point /\
datafrog_opt_subset Origin1 Origin2 Point .
Theorem Lemma92:
forall Origin1,
forall Origin2,
forall Origin9,
forall Point2,
forall Point3,
dying_can_reach Origin1 Origin2 Point2 Point3 ->
my_subset Origin2 Origin9 Point2 ->
origin_live_on_entry Origin9 Point3 ->
(
dying_can_reach_live Origin1 Origin9 Point2 Point3 \/
(
exists Origin5,
dying_can_reach_live Origin1 Origin5 Point2 Point3 /\
origin_live_on_entry Origin5 Point3 /\
my_subset Origin5 Origin9 Point2
)
).
induction on 2.
intros.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point3.
case H4.
search.
case H2.
search.
assert dying_can_reach Origin1 Origin3 Point2 Point3.
apply IH to H8 H7 H3.
search.
Theorem Lemma90:
forall Loan,
forall Origin1,
forall Origin9,
forall Point2,
forall Point3,
dying_region_requires Origin1 Point2 Point3 Loan ->
my_subset Origin1 Origin9 Point2 ->
origin_live_on_entry Origin9 Point3 ->
(
datafrog_opt_origin_contains_loan_on_entry Origin9 Loan Point3 \/
(
exists Origin5,
datafrog_opt_origin_contains_loan_on_entry Origin5 Loan Point3 /\
origin_live_on_entry Origin5 Point3 /\
my_subset Origin5 Origin9 Point2
)
).
intros.
assert dying_can_reach_origins Origin1 Point2 Point3.
case H2.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point3.
case H7.
search.
assert dying_can_reach Origin1 Origin2 Point2 Point3.
apply Lemma92 to H9 H6 H3.
case H10.
search.
search.
Theorem MySubsetConcat:
forall Origin1,
forall Origin2,
forall Origin3,
forall Point,
my_subset Origin1 Origin2 Point ->
my_subset Origin2 Origin3 Point ->
my_subset Origin1 Origin3 Point.
induction on 1.
intros.
case H1.
search.
apply IH to H4 H2.
search.
Theorem MySubsetPoint:
(
forall Origin0,
forall Origin9,
forall Point1,
forall Point2,
cfg_edge Point1 Point2 ->
my_subset Origin0 Origin9 Point1 ->
origin_live_on_entry Origin0 Point2 ->
origin_live_on_entry Origin9 Point2 ->
my_subset Origin0 Origin9 Point2
) /\ (
forall Origin0,
forall Origin1,
forall Origin2,
forall Origin9,
forall Point1,
forall Point2,
cfg_edge Point1 Point2 ->
live_to_dying_regions Origin0 Origin1 Point1 Point2 ->
dying_can_reach Origin1 Origin2 Point1 Point2 ->
my_subset Origin2 Origin9 Point1 ->
origin_live_on_entry Origin9 Point2 ->
my_subset Origin0 Origin9 Point2
) /\ (
forall Origin0,
forall Origin1,
forall Origin9,
forall Point1,
forall Point2,
cfg_edge Point1 Point2 ->
live_to_dying_regions Origin0 Origin1 Point1 Point2 ->
my_subset Origin1 Origin9 Point1 ->
origin_live_on_entry Origin9 Point2 ->
my_subset Origin0 Origin9 Point2
).
induction on 2 4 3.
split.
intros.
case H2.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point2.
case H7.
apply IH to H1 H6 H8 H4.
search.
case H6.
assert live_to_dying_regions Origin0 Origin2 Point1 Point2.
assert dying_can_reach Origin2 Origin9 Point1 Point2.
assert dying_can_reach_live Origin2 Origin9 Point1 Point2.
search.
assert live_to_dying_regions Origin0 Origin2 Point1 Point2.
assert dying_can_reach Origin2 Origin1 Point1 Point2.
apply IH1 to H1 H11 H12 H10 H4.
search.
intros.
case H4.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point2.
case H7.
search.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point2.
case H8.
apply OriginLiveAxiom with Origin = Origin3 , Point = Point2.
case H10.
apply IH to H1 H7 H11 H5.
search.
assert live_to_dying_regions Origin2 Origin3 Point1 Point2.
apply IH2 to H1 H12 H7 H5.
search.
assert dying_can_reach Origin1 Origin3 Point1 Point2.
apply IH1 to H1 H2 H10 H7 H5.
search.
intros.
case H3.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point2.
case H7.
apply IH to H1 H6 H8 H4.
search.
assert dying_can_reach Origin1 Origin2 Point1 Point2.
apply IH1 to H1 H2 H9 H6 H4.
search.
Theorem SubsetNaive2My:
forall Point2,
forall Origin1,
forall Origin9,
naive_subset Origin1 Origin9 Point2 ->
my_subset Origin1 Origin9 Point2.
induction on 1.
intros.
case H1.
search.
apply IH to H2.
case H6.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point2.
case H9.
case MySubsetPoint.
apply H11 to H3 H8 H10 H5.
search.
assert live_to_dying_regions Origin1 Origin2 Point1 Point2.
case MySubsetPoint.
apply H14 to H3 H11 H8 H5.
search.
apply IH to H2.
apply IH to H3.
apply MySubsetConcat to H4 H5.
search.
Theorem MyOriginConcat:
forall Origin1,
forall Origin9,
forall Point,
forall Loan,
my_origin_contains_loan_on_entry Origin1 Loan Point ->
my_subset Origin1 Origin9 Point ->
my_origin_contains_loan_on_entry Origin9 Loan Point.
induction on 2.
intros.
case H2.
search.
assert my_origin_contains_loan_on_entry Origin2 Loan Point.
apply IH to H5 H4.
search.
Theorem MyOriginPoint:
(
forall Point1,
forall Point2,
forall Loan,
forall Origin9,
cfg_edge Point1 Point2 ->
my_origin_contains_loan_on_entry Origin9 Loan Point1 ->
origin_live_on_entry Origin9 Point2 ->
not_loan_killed_at Loan Point1 ->
my_origin_contains_loan_on_entry Origin9 Loan Point2
) /\ (
forall Point1,
forall Point2,
forall Loan,
forall Origin2,
forall Origin9,
cfg_edge Point1 Point2 ->
my_subset Origin2 Origin9 Point1 ->
my_origin_contains_loan_on_entry Origin2 Loan Point1 ->
origin_live_on_entry Origin9 Point2 ->
( origin_live_on_entry Origin2 Point2 -> false ) ->
not_loan_killed_at Loan Point1 ->
my_origin_contains_loan_on_entry Origin9 Loan Point2
).
induction on 2 3.
split.
intros.
case H2.
search.
apply OriginLiveAxiom with Origin = Origin1 , Point = Point2.
assert my_subset Origin1 Origin9 Point1.
case H7.
apply IH to H1 H5 H9 H4.
search.
apply IH1 to H1 H8 H5 H3 H9 H4.
search.
intros.
case H3.
assert dying_region_requires Origin2 Point1 Point2 Loan.
apply Lemma90 to H8 H2 H4.
case H9.
search.
case MySubsetPoint.
apply H13 to H1 H12 H11 H4.
assert my_origin_contains_loan_on_entry Origin5 Loan Point2.
apply MyOriginConcat to H17 H16.
search.
apply OriginLiveAxiom with Origin = Origin1 , Point = Point2.
case H9.
assert my_subset Origin1 Origin9 Point1.
case MySubsetPoint.
apply H12 to H1 H11 H10 H4.
apply IH to H1 H7 H10 H6.
apply MyOriginConcat to H16 H15.
search.
assert my_subset Origin1 Origin9 Point1.
apply IH1 to H1 H11 H7 H4 H10 H6.
search.
Theorem OriginNaive2My:
forall Point2,
forall Origin9,
forall Loan,
naive_origin_contains_loan_on_entry Origin9 Loan Point2 ->
my_origin_contains_loan_on_entry Origin9 Loan Point2.
induction on 1.
intros.
case H1.
search.
apply IH to H2.
apply SubsetNaive2My to H3.
apply MyOriginConcat to H4 H5.
search.
apply IH to H2.
case MyOriginPoint.
apply H7 to H4 H6 H5 H3.
search.
Theorem Lemma97:
forall Point,
forall Loan,
forall Origin1,
forall Origin9,
dead_borrow_region_can_reach_dead Origin1 Point Loan ->
my_subset Origin1 Origin9 Point ->
origin_live_on_entry Origin9 Point ->
datafrog_opt_loan_live_at Loan Point.
induction on 2.
intros.
case H2.
search.
apply OriginLiveAxiom with Origin = Origin2 , Point = Point.
case H6.
search.
assert dead_borrow_region_can_reach_dead Origin2 Point Loan.
apply IH to H8 H5 H3.
search.
Theorem Lemma98:
forall Point,
forall Loan,
forall Origin1,
forall Origin9,
loan_issued_at Origin1 Loan Point ->
my_subset Origin1 Origin9 Point ->
origin_live_on_entry Origin9 Point ->
datafrog_opt_loan_live_at Loan Point.
intros.
apply OriginLiveAxiom with Origin = Origin1 , Point = Point.
case H4.
search.
assert dead_borrow_region_can_reach_dead Origin1 Point Loan.
apply Lemma97 to H6 H2 H3.
search.
Theorem Lemma99:
(
forall Origin9,
forall Loan,
forall Point,
my_origin_contains_loan_on_entry Origin9 Loan Point ->
origin_live_on_entry Origin9 Point ->
datafrog_opt_loan_live_at Loan Point
) /\ (
forall Origin5,
forall Origin9,
forall Loan,
forall Point,
my_origin_contains_loan_on_entry Origin5 Loan Point ->
my_subset Origin5 Origin9 Point ->
( origin_live_on_entry Origin5 Point -> false ) ->
origin_live_on_entry Origin9 Point ->
datafrog_opt_loan_live_at Loan Point
).
induction on 1 1.
split.
intros.
case H1.
search.
apply OriginLiveAxiom with Origin = Origin1 , Point = Point.
case H5.
apply IH to H3 H6.
search.
assert my_subset Origin1 Origin9 Point.
apply IH1 to H3 H7 H6 H2.
search.
intros.
case H1.
case H5.
apply Lemma98 to H6 H2 H4.
search.
search.
case H7.
search.
apply OriginLiveAxiom with Origin = Origin1 , Point = Point.
case H7.
apply IH to H5 H8.
search.
assert my_subset Origin1 Origin9 Point.
apply IH1 to H5 H9 H8 H4.
search.
Theorem Naive2DatafrogOpt:
forall Loan,
forall Point,
naive_errors Loan Point ->
datafrog_opt_errors Loan Point.
intros.
case H1.
case H3.
apply OriginNaive2My to H4.
unfold.
search.
case Lemma99.
apply H7 to H6 H5.
search.