Skip to content

Commit be6530c

Browse files
committed
Towards supporting universe branch.
1 parent ce07ca0 commit be6530c

9 files changed

+126
-275
lines changed

lib/common/Pulse.Lib.PCM.Raise.fst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let raise_compatible
3030
op p frame x == y
3131
returns compatible (raise u#a u#b p) (U.raise_val x) (U.raise_val y)
3232
with _ . (
33-
assert (composable (raise p) (U.raise_val x) (U.raise_val frame))
33+
assert (composable (raise u#a u#b p) (U.raise_val x) (U.raise_val frame))
3434
)
3535

3636

@@ -49,7 +49,7 @@ let raise_refine
4949
let ya = f va in
5050
let y = U.raise_val ya in
5151
assert (compatible p ya va);
52-
raise_compatible p ya va;
52+
raise_compatible u#a u#b p ya va;
5353
y
5454

5555
let raise_upd
@@ -60,5 +60,5 @@ let raise_refine
6060
= fun x ->
6161
let ra = f (U.downgrade_val x) in
6262
let res = U.raise_val ra in
63-
raise_compatible p y ra;
63+
raise_compatible u#a u#b p y ra;
6464
res

lib/core/PulseCore.BaseHeapSig.fst

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ let star_equiv (p q:slprop) (m:mem u#a)
2727
let slprop_extensionality (p q:slprop)
2828
: Lemma ((forall c. interp p c <==> interp q c) ==> p == q)
2929
[SMTPat (p == q)]
30-
= introduce (forall c. interp p c <==> interp q c) ==> p == q with _.
30+
= introduce (forall c. H2.interp p c <==> interp q c) ==> p == q with _.
3131
H2.slprop_extensionality p q
3232

33-
let star_commutative (p q: slprop) : Lemma (star p q == star q p) =
33+
let star_commutative (p q: slprop u#a) : Lemma (star p q == star q p) =
3434
introduce forall c. interp (star p q) c <==> interp (star q p) c with (
3535
star_equiv p q c;
3636
star_equiv q p c;
37-
introduce forall (a b: mem). disjoint_mem a b <==> disjoint_mem b a with H2.disjoint_sym a b;
38-
introduce forall (h0 h1: mem). disjoint_mem h0 h1 ==> disjoint_mem h1 h0 /\ join_mem h0 h1 == join_mem h1 h0 with
37+
introduce forall (a b: mem u#a). disjoint_mem a b <==> disjoint_mem b a with H2.disjoint_sym a b;
38+
introduce forall (h0 h1: mem u#a). disjoint_mem h0 h1 ==> disjoint_mem h1 h0 /\ join_mem h0 h1 == join_mem h1 h0 with
3939
introduce _ ==> _ with _. H2.join_commutative h0 h1
4040
);
4141
slprop_extensionality (star p q) (star q p)
@@ -124,30 +124,29 @@ let lower (frame: slprop) (m: mem) : p:H2.slprop { forall h. H2.interp p h <==>
124124

125125
let ac_lemmas ()
126126
: Lemma (
127-
(forall p q r. (p `star` q) `star` r == p `star` (q `star` r)) /\
128-
(forall p q. p `star` q == q `star` p) /\
129-
(forall p. p `star` emp == p)
127+
(forall (p q r : slprop u#a). (p `star` q) `star` r == p `star` (q `star` r)) /\
128+
(forall (p q: slprop u#a). p `star` q == q `star` p) /\
129+
(forall (p: slprop u#a). p `star` emp == p)
130130
)
131-
= FStar.Classical.forall_intro_3 (star_associative);
132-
FStar.Classical.forall_intro_2 (star_commutative);
133-
FStar.Classical.forall_intro emp_unit
131+
= FStar.Classical.forall_intro_3 (star_associative u#a);
132+
FStar.Classical.forall_intro_2 (star_commutative u#a);
133+
FStar.Classical.forall_intro (emp_unit u#a)
134134

135135
let destruct_star_l (p q:slprop) (m:mem)
136136
: Lemma (interp (p `star` q) m ==> interp p m)
137137
= star_equiv p q m
138138

139-
let destruct_star (p q:slprop) (m:mem)
139+
let destruct_star (p q:slprop u#a) (m:mem)
140140
: Lemma (interp (p `star` q) m ==> interp p m /\ interp q m)
141-
= ac_lemmas ();
141+
= ac_lemmas u#a ();
142142
destruct_star_l p q m;
143143
destruct_star_l q p m
144144

145145
let elim_init (fp: H2.slprop) (frame:slprop u#a) (m:mem)
146146
: Lemma
147147
(requires interp (fp `star` frame) m)
148148
(ensures H2.interp fp m /\ H2.interp (fp `H2.star` lower frame m) m)
149-
= ac_lemmas ();
150-
destruct_star fp frame m;
149+
= destruct_star fp frame m;
151150
assert H2.interp fp m;
152151
star_equiv fp frame m;
153152
let m1 = IndefiniteDescription.indefinite_description_ghost _ fun m1 -> exists m2.
@@ -190,9 +189,8 @@ let intro_fin (post: H2.slprop) (frame:slprop) (m:mem)
190189
assert disjoint_mem m1 m2;
191190
assert join_mem m1 m2 == m;
192191
star_equiv post frame m;
193-
assert interp (post `star` frame) m;
194-
ac_lemmas ()
195-
192+
assert interp (post `star` frame) m
193+
196194
let lift_heap_action
197195
(#fp:H2.slprop u#a)
198196
(#a:Type u#b)

lib/core/PulseCore.Heap.fst

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ let ctr (h: heap) : nat = Seq.length h
3333
let select i h =
3434
if i < ctr h then Seq.index h i else None
3535

36-
let empty_heap' n = Seq.create n None
36+
let empty_heap' n : heap u#a = Seq.create n None
3737

38-
let select_empty_heap' a n : Lemma (select a (empty_heap' n) == None) [SMTPat (select a (empty_heap' n))] =
39-
reveal_opaque (`%select) (select a (empty_heap' n))
38+
let select_empty_heap' a n : Lemma (select a (empty_heap' u#a n) == None) [SMTPat (select a (empty_heap' u#a n))] =
39+
reveal_opaque (`%select) (select a (empty_heap' u#a n))
4040

4141
let empty_heap = empty_heap' 0
4242

@@ -59,11 +59,11 @@ let update_addr' (m:heap) (a:addr { a < ctr m }) (c:option cell)
5959
: heap
6060
= Seq.upd m a c
6161

62-
let select_update_addr' m a b c :
62+
let select_update_addr' (m: heap u#a) a b c :
6363
Lemma (select a (update_addr' m b c) ==
6464
(if a = b then c else select a m))
6565
[SMTPat (select a (update_addr' m b c))] =
66-
reveal_opaque (`%select) (select a)
66+
reveal_opaque (`%select) (select u#a a)
6767

6868
let update_addr (m:heap) (a:addr { a < ctr m }) (c:cell)
6969
: heap
@@ -151,7 +151,7 @@ let join (m0:heap) (m1:heap{disjoint m0 m1})
151151
let ctr_join_def m0 m1 : Lemma (ctr (join m0 m1) == max (ctr m0) (ctr m1)) [SMTPat (ctr (join m0 m1))] =
152152
reveal_opaque (`%join) (join m0 m1)
153153

154-
let select_join_def a m0 m1 :
154+
let select_join_def a (m0: heap u#a) m1 :
155155
Lemma (select a (join m0 m1) ==
156156
(match select a m0, select a m1 with
157157
| None, None -> None
@@ -160,7 +160,7 @@ let select_join_def a m0 m1 :
160160
| Some c0, Some c1 ->
161161
Some (join_cells c0 c1)))
162162
[SMTPat (select a (join m0 m1))] =
163-
reveal_opaque (`%select) (select a);
163+
reveal_opaque (`%select) (select u#a a);
164164
reveal_opaque (`%join) (join m0 m1)
165165

166166
let disjoint_join_cells_assoc (c0 c1 c2:cell u#h)
@@ -202,14 +202,14 @@ let disjoint_join' (m0 m1 m2:heap u#h)
202202
let mem_equiv (m0 m1:heap) =
203203
ctr m0 == ctr m1 /\ forall a. select a m0 == select a m1
204204

205-
let mem_equiv_eq (m0 m1:heap)
205+
let mem_equiv_eq (m0 m1:heap u#a)
206206
: Lemma
207207
(requires
208208
m0 `mem_equiv` m1)
209209
(ensures
210210
m0 == m1)
211211
[SMTPat (m0 `mem_equiv` m1)]
212-
= reveal_opaque (`%select) select; assert Seq.equal m0 m1
212+
= reveal_opaque (`%select) (select u#a); assert Seq.equal m0 m1
213213

214214
let join_cells_commutative (c0:cell u#h) (c1:cell u#h{disjoint_cells c0 c1})
215215
: Lemma (disjoint_cells_sym c0 c1; join_cells c0 c1 == join_cells c1 c0)
@@ -422,24 +422,11 @@ let affine_star p q h = ()
422422

423423
let equiv_symmetric (p1 p2:slprop u#a) = ()
424424
let equiv_extensional_on_star (p1 p2 p3:slprop u#a) = ()
425-
let emp_unit p
426-
= let emp_unit_1 p m
427-
: Lemma
428-
(requires interp p m)
429-
(ensures interp (p `star` emp) m)
430-
[SMTPat (interp (p `star` emp) m)]
431-
= assert (disjoint empty_heap m);
432-
assert (interp (p `star` emp) (join m empty_heap));
433-
assert (mem_equiv m (join m empty_heap))
434-
in
435-
let emp_unit_2 p m
436-
: Lemma
437-
(requires interp (p `star` emp) m)
438-
(ensures interp p m)
439-
[SMTPat (interp (p `star` emp) m)]
440-
= affine_star p emp m
441-
in
442-
()
425+
426+
let emp_unit (p: slprop u#a) =
427+
introduce forall (m: heap u#a). interp p m <==> interp (p `star` emp) m with
428+
(join_empty m; affine_star p emp m)
429+
443430

444431
let intro_emp h = ()
445432

@@ -793,21 +780,17 @@ let sel_action' (#a:_) (#pcm:_)
793780
= sel_v r v0 h
794781

795782
let refined_pre_action (#immut:bool)
796-
(#[T.exact (`trivial_pre)]pre:heap ->prop)
797-
(#[T.exact (`trivial_pre)]post:heap -> prop)
798783
(fp0:slprop) (a:Type) (fp1:a -> slprop) =
799784
m0:full_hheap fp0 ->
800785
Pure (x:a &
801786
full_hheap (fp1 x))
802-
(requires pre m0)
787+
(requires True)
803788
(ensures fun (| x, m1 |) ->
804-
post m1 /\
805789
(forall frame. frame_related_heaps m0 m1 fp0 (fp1 x) frame immut))
806790

807-
#restart-solver
808-
let refined_pre_action_as_action #immut #pre #post (#fp0:slprop) (#a:Type) (#fp1:a -> slprop)
809-
($f:refined_pre_action #immut #pre #post fp0 a fp1)
810-
: action #immut #pre #post fp0 a fp1
791+
let refined_pre_action_as_action #immut (#fp0:slprop) (#a:Type) (#fp1:a -> slprop)
792+
($f:refined_pre_action #immut fp0 a fp1)
793+
: action #immut fp0 a fp1
811794
= let g : pre_action fp0 a fp1 = fun m -> f m in
812795
g
813796

@@ -1162,10 +1145,10 @@ let pts_to_not_null_action #a #pcm r v
11621145
refined_pre_action_as_action g
11631146

11641147
////////////////////////////////////////////////////////////////////////////////
1165-
let select_snoc (h: heap) (c: option cell) a :
1148+
let select_snoc (h: heap u#a) (c: option cell) a :
11661149
Lemma (select a (Seq.snoc h c) == (if a = ctr h then c else select a h))
11671150
[SMTPat (select a (Seq.snoc h c))] =
1168-
reveal_opaque (`%select) (select a)
1151+
reveal_opaque (`%select) (select u#a a)
11691152

11701153
let extend_full_heap_with (h: full_heap) (c: cell {full_cell c}) :
11711154
h':full_heap {
@@ -1220,13 +1203,13 @@ let extend #a #pcm
12201203
#push-options "--z3rlimit_factor 4 --max_fuel 1 --max_ifuel 1"
12211204
#restart-solver
12221205
let frame (#a:Type)
1223-
(#immut #hpre #hpost:_)
1206+
#immut
12241207
(#pre:slprop)
12251208
(#post:a -> slprop)
12261209
(frame:slprop)
12271210
($f:action pre a post)
12281211
= let g
1229-
: refined_pre_action #immut #hpre #hpost
1212+
: refined_pre_action #immut
12301213
(pre `star` frame) a (fun x -> post x `star` frame)
12311214
= fun h0 ->
12321215
assert (interp (pre `star` frame) h0);
@@ -1264,15 +1247,14 @@ let pts_to_evolve (#a:Type u#a) (#pcm:_) (r:ref a pcm) (x y : a) (h:heap)
12641247
compatible_trans pcm y x v'
12651248

12661249
let erase_action_result
1267-
(#pre #post:_)
12681250
(#immut:_)
12691251
(#fp:slprop)
12701252
(#a:Type)
12711253
(#fp':a -> slprop)
1272-
(act:action #immut #pre #post fp a fp')
1273-
: action #immut #pre #post fp (erased a) (fun x -> fp' x)
1254+
(act:action #immut fp a fp')
1255+
: action #immut fp (erased a) (fun x -> fp' x)
12741256
= let g
1275-
: refined_pre_action #immut #pre #post fp (erased a) (fun x -> fp' x)
1257+
: refined_pre_action #immut fp (erased a) (fun x -> fp' x)
12761258
= fun h ->
12771259
let (| x, h1 |) = act h in
12781260
let y : erased a = hide x in
@@ -1282,13 +1264,12 @@ let erase_action_result
12821264
refined_pre_action_as_action g
12831265

12841266
let erase_action_result_identity
1285-
(#pre #post:_)
12861267
(#immut:_)
12871268
(#fp:slprop)
12881269
(#a:Type)
12891270
(#fp':a -> slprop)
1290-
(act:action #immut #pre #post fp a fp')
1291-
(h:full_hheap fp { pre h})
1271+
(act:action #immut fp a fp')
1272+
(h:full_hheap fp)
12921273
: Lemma (
12931274
let (| x, h1 |) = act h in
12941275
let (| y, h2 |) = erase_action_result act h in

lib/core/PulseCore.Heap.fsti

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -390,14 +390,11 @@ let full_hheap fp = h:hheap fp { full_heap_pred h }
390390
The base type for an action is indexed by two separation logic propositions, representing
391391
the heap specification of the action before and after.
392392
*)
393-
let trivial_pre (h:heap) : prop = True
394393
module T = FStar.Tactics
395-
let pre_action (#[T.exact (`trivial_pre)]pre:heap -> prop)
396-
(#[T.exact (`trivial_pre)]post:heap -> prop)
397-
(fp:slprop u#a)
394+
let pre_action (fp:slprop u#a)
398395
(a:Type u#b)
399396
(fp':a -> slprop u#a)
400-
= h0:full_hheap fp { pre h0 } -> res:(x:a & full_hheap (fp' x)) { post (dsnd res) }
397+
= full_hheap fp -> x:a & full_hheap (fp' x)
401398

402399
(**
403400
This is how the heaps before and after the action relate:
@@ -422,24 +419,21 @@ let action_related_heaps
422419
*)
423420
let is_frame_preserving
424421
(#a: Type u#a)
425-
(#pre #post:_)
426422
(#fp: slprop u#b)
427423
(#fp': a -> slprop u#b)
428424
(immut:bool)
429-
(f:pre_action #pre #post fp a fp')
425+
(f:pre_action fp a fp')
430426
=
431-
forall (frame: slprop u#b) (h0:full_hheap (fp `star` frame) { pre h0 }).
427+
forall (frame: slprop u#b) (h0:full_hheap (fp `star` frame)).
432428
(affine_star fp frame h0;
433429
let (| x, h1 |) = f h0 in
434430
interp (fp' x `star` frame) h1 /\
435431
action_related_heaps #immut h0 h1)
436432

437433
(** Every action is frame-preserving *)
438434
let action (#[T.exact (`mut_heap)] immut:bool)
439-
(#[T.exact (`trivial_pre)]pre:heap -> prop)
440-
(#[T.exact (`trivial_pre)]post:heap -> prop)
441435
(fp:slprop u#b) (a:Type u#a) (fp':a -> slprop u#b) =
442-
f:pre_action #pre #post fp a fp'{ is_frame_preserving immut f }
436+
f:pre_action fp a fp'{ is_frame_preserving immut f }
443437

444438
(**
445439
Two heaps [h0] and [h1] are frame-related if you can get from [h0] to [h1] with a
@@ -460,13 +454,11 @@ let action_framing
460454
(#immut:bool)
461455
(#fp: slprop u#b)
462456
(#fp': a -> slprop u#b)
463-
(#pre #post: heap u#b -> prop)
464-
($f:action #immut #pre #post fp a fp')
465-
(frame:slprop) (h0:full_hheap (fp `star` frame) { pre h0 })
457+
($f:action #immut fp a fp')
458+
(frame:slprop) (h0:full_hheap (fp `star` frame))
466459
: Lemma (
467460
affine_star fp frame h0;
468461
let (| x, h1 |) = f h0 in
469-
post h1 /\
470462
frame_related_heaps h0 h1 fp (fp' x) frame immut
471463
)
472464
=
@@ -628,34 +620,32 @@ val extend
628620
(fun r -> pts_to r x)
629621

630622
val frame (#a:Type)
631-
#immut #hpre #hpost
623+
#immut
632624
(#pre:slprop)
633625
(#post:a -> slprop)
634626
(frame:slprop)
635-
($f:action #immut #hpre #hpost pre a post)
636-
: action #immut #hpre #hpost (pre `star` frame) a (fun x -> post x `star` frame)
627+
($f:action #immut pre a post)
628+
: action #immut (pre `star` frame) a (fun x -> post x `star` frame)
637629

638630
val pts_to_evolve (#a:Type u#a) (#pcm:_) (r:ref a pcm) (x y : a) (h:heap)
639631
: Lemma (requires (interp (pts_to r x) h /\ compatible pcm y x))
640632
(ensures (interp (pts_to r y) h))
641633

642634
val erase_action_result
643-
(#pre #post:_)
644635
(#immut:_)
645636
(#fp:slprop)
646637
(#a:Type)
647638
(#fp':a -> slprop)
648-
(act:action #immut #pre #post fp a fp')
649-
: action #immut #pre #post fp (erased a) (fun x -> fp' x)
639+
(act:action #immut fp a fp')
640+
: action #immut fp (erased a) (fun x -> fp' x)
650641

651642
val erase_action_result_identity
652-
(#pre #post:_)
653643
(#immut:_)
654644
(#fp:slprop)
655645
(#a:Type)
656646
(#fp':a -> slprop)
657-
(act:action #immut #pre #post fp a fp')
658-
(h:full_hheap fp { pre h})
647+
(act:action #immut fp a fp')
648+
(h:full_hheap fp)
659649
: Lemma (
660650
let (| x, h1 |) = act h in
661651
let (| y, h2 |) = erase_action_result act h in

0 commit comments

Comments
 (0)