Skip to content

Commit 9e7fc2b

Browse files
committed
wip
1 parent 427b92c commit 9e7fc2b

File tree

7 files changed

+293
-101
lines changed

7 files changed

+293
-101
lines changed

lib/pulse/lib/Pulse.Lib.BetterInv.fst

Lines changed: 91 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,12 @@ let inv (i: iname) (p: slprop) =
2121
let aux #p (inst: placeless p) l1 l2 =
2222
fun () -> inst l1 l2
2323

24-
ghost fn placeless_inv i p {| inst: placeless p |} : placeless (inv i p) = l1 l2 {
25-
ghost_impersonate l1 (on l1 (inv i p)) (on l2 (inv i p)) fn _ {
26-
on_elim (inv i p);
27-
unfold inv i p; with l_ l'. _;
28-
loc_gather l1 #l_;
29-
drop_ (move_tag l_ l' p _ _);
30-
ghost_impersonate l2 (C.inv i (on l' p)) (on l2 (inv i p)) fn _ {
31-
fold move_tag l2 l' p (aux #p inst l2 l') (aux #p inst l' l2);
32-
loc_dup l2;
33-
fold inv i p;
34-
on_intro (inv i p);
35-
}
36-
}
37-
}
38-
39-
ghost fn is_send_inv i p {| is_send p |} : is_send (inv i p) = l1 l2 {
24+
ghost fn move i p l1 l2
25+
(fwd: unit -> stt_ghost unit emp_inames (on l1 p) (fun _ -> on l2 p))
26+
(bwd: unit -> stt_ghost unit emp_inames (on l2 p) (fun _ -> on l1 p))
27+
requires on l1 (inv i p)
28+
ensures on l2 (inv i p)
29+
{
4030
ghost_impersonate l1 (on l1 (inv i p)) (on l2 (inv i p)) fn _ {
4131
on_elim (inv i p);
4232
unfold inv i p; with l_ l' f g. _;
@@ -47,15 +37,15 @@ ghost fn is_send_inv i p {| is_send p |} : is_send (inv i p) = l1 l2 {
4737
requires on l2 p
4838
ensures on l' p
4939
{
50-
is_send_elim p l1;
40+
bwd ();
5141
let f = f; f ()
5242
};
5343
ghost fn g' ()
5444
requires on l' p
5545
ensures on l2 p
5646
{
5747
let g = g; g ();
58-
is_send_elim p l2;
48+
fwd ();
5949
};
6050
fold move_tag l2 l' p f' g';
6151
loc_dup l2;
@@ -65,6 +55,18 @@ ghost fn is_send_inv i p {| is_send p |} : is_send (inv i p) = l1 l2 {
6555
}
6656
}
6757

58+
ghost fn placeless_inv i p {| inst: placeless p |} : placeless (inv i p) = l1 l2 {
59+
move i p l1 l2
60+
fn _ { inst l1 l2 }
61+
fn _ { inst l2 l1 }
62+
}
63+
64+
ghost fn is_send_inv i p {| is_send p |} : is_send (inv i p) = l1 l2 {
65+
move i p l1 l2
66+
fn _ { is_send_elim p l2 }
67+
fn _ { is_send_elim p l1 }
68+
}
69+
6870
ghost fn dup_inv i p () : duplicable_f (inv i p) = {
6971
unfold inv i p; with l l' f g. _;
7072
dup (C.inv i (on l' p)) ();
@@ -77,26 +79,85 @@ ghost fn dup_inv i p () : duplicable_f (inv i p) = {
7779
instance duplicable_inv i p : duplicable (inv i p) =
7880
{ dup_f = dup_inv i p }
7981

80-
open PulseCore.Observability
82+
ghost fn new_invariant (p: slprop)
83+
requires p
84+
returns i: iname
85+
ensures inv i p
86+
{
87+
loc_get (); with l. assert loc l;
88+
on_intro p;
89+
let i = C.new_invariant (on l p) #_;
90+
ghost fn f () requires on l p ensures on l p {};
91+
fold move_tag l l p f f;
92+
fold inv i p;
93+
i
94+
}
95+
96+
inline_for_extraction noextract
97+
ghost fn with_inv_g u#a (a: Type u#a)
98+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
99+
(k: unit -> stt_ghost a is (pre ** p) (fun x -> post x ** p))
100+
opens add_inv is i
101+
preserves inv i p
102+
requires later_credit 1
103+
requires pre
104+
returns x:a
105+
ensures post x
106+
{
107+
unfold inv i p; with l l' f g. _;
108+
let x = with_invariant_g #a
109+
#(pre ** later_credit 1 ** loc l)
110+
#(fun x -> post x ** loc l) #is #(on l' p) i fn _ {
111+
later_elim (on l' p);
112+
{ let g=g; g() };
113+
on_elim p;
114+
let x = k ();
115+
on_intro p;
116+
{ let f=f; f() };
117+
later_intro (on l' p);
118+
x
119+
};
120+
fold inv i p;
121+
x
122+
}
81123

82-
unobservable fn with_inv_unobs u#a (#a: Type u#a) #is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
83-
(k: unit -> stt_atomic a #Neutral is (pre ** later p) (fun x -> post x ** later p))
84-
opens is
124+
inline_for_extraction noextract
125+
atomic fn with_inv_atomic u#a (a: Type u#a)
126+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
127+
(k: unit -> stt_atomic a #Observable is (pre ** p) (fun x -> post x ** p))
128+
opens add_inv is i
85129
preserves inv i p
130+
requires later_credit 1
86131
requires pre
87132
returns x:a
88133
ensures post x
89134
{
90-
unfold inv i p; with l_ l' f g. _;
91-
assume pure (inames_subset (add_inv is i) is);
92-
let x = with_invariant #a #Neutral #pre #post #is #(on l' p) i fn _ {
93-
later_on l' p;
94-
// { let g=g; g() };
95-
admit ();
135+
unfold inv i p; with l l' f g. _;
136+
let x = with_invariant #a #Observable
137+
#(pre ** later_credit 1 ** loc l)
138+
#(fun x -> post x ** loc l) #is #(on l' p) i fn _ {
139+
later_elim (on l' p);
140+
{ let g=g; g() };
141+
on_elim p;
96142
let x = k ();
97-
on_later l' p;
143+
on_intro p;
144+
{ let f=f; f() };
145+
later_intro (on l' p);
98146
x
99147
};
100-
admit ();
101148
fold inv i p;
149+
x
150+
}
151+
152+
inline_for_extraction noextract
153+
fn with_inv_stt u#a (a: Type u#a)
154+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
155+
(k: unit -> stt_atomic a #Observable is (pre ** p) (fun x -> post x ** p))
156+
preserves inv i p
157+
requires pre
158+
returns x:a
159+
ensures post x
160+
{
161+
later_credit_buy 1;
162+
with_inv_atomic a is i p pre post k
102163
}

lib/pulse/lib/Pulse.Lib.BetterInv.fsti

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,52 @@ module Pulse.Lib.BetterInv
33
open Pulse.Lib.Core
44
open Pulse.Lib.SendSync
55
open Pulse.Class.Duplicable
6+
open PulseCore.Observability
67

78
val inv (i: iname) (p: slprop) : slprop
89

10+
ghost fn move i p l1 l2
11+
(fwd: unit -> stt_ghost unit emp_inames (on l1 p) (fun _ -> on l2 p))
12+
(bwd: unit -> stt_ghost unit emp_inames (on l2 p) (fun _ -> on l1 p))
13+
requires on l1 (inv i p)
14+
ensures on l2 (inv i p)
15+
916
instance val placeless_inv i p {| placeless p |} : placeless (inv i p)
1017
instance val is_send_inv i p {| is_send p |} : is_send (inv i p)
1118
instance val duplicable_inv i p : duplicable (inv i p)
19+
20+
ghost fn new_invariant (p: slprop)
21+
requires p
22+
returns i: iname
23+
ensures inv i p
24+
25+
inline_for_extraction noextract
26+
ghost fn with_inv_g u#a (a: Type u#a)
27+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
28+
(k: unit -> stt_ghost a is (pre ** p) (fun x -> post x ** p))
29+
opens add_inv is i
30+
preserves inv i p
31+
requires later_credit 1
32+
requires pre
33+
returns x:a
34+
ensures post x
35+
36+
inline_for_extraction noextract
37+
atomic fn with_inv_atomic u#a (a: Type u#a)
38+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
39+
(k: unit -> stt_atomic a #Observable is (pre ** p) (fun x -> post x ** p))
40+
opens add_inv is i
41+
preserves inv i p
42+
requires later_credit 1
43+
requires pre
44+
returns x:a
45+
ensures post x
46+
47+
inline_for_extraction noextract
48+
fn with_inv_stt u#a (a: Type u#a)
49+
is (i: iname { not (mem_inv is i) }) (p: slprop) pre (post: a->slprop)
50+
(k: unit -> stt_atomic a #Observable is (pre ** p) (fun x -> post x ** p))
51+
preserves inv i p
52+
requires pre
53+
returns x:a
54+
ensures post x

0 commit comments

Comments
 (0)