Skip to content

Commit 2d21b98

Browse files
authored
Merge pull request #483 from FStarLang/gebner_phase1_matcher
Phase-1 matcher
2 parents e243a9e + 5c1263a commit 2d21b98

File tree

161 files changed

+1767
-4857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+1767
-4857
lines changed

lib/common/Pulse.Lib.Core.fsti

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,16 @@ let match_rewrite_tac (_:unit) : T.Tac unit =
613613
T.mapply (`slprop_equiv_ext');
614614
T.trefl ()
615615

616+
let match_rename_tac (_:unit) : T.Tac unit =
617+
let open T in
618+
let b = T.nth_var (-1) in
619+
T.norm []; // Needed, or otherwise the `tcut` in grewrite_eq can fail, unsure why.
620+
try (
621+
T.grewrite_eq b;
622+
T.trefl ()
623+
)
624+
with _ -> T.smt()
625+
616626
[@@deprecated "Use (rewrite .. as .. by ..) syntax instead!"]
617627
val rewrite_by (p:slprop) (q:slprop)
618628
(t:unit -> T.Tac unit)

lib/pulse/lib/Pulse.Lib.AVLTree.fst

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,16 @@ fn cases_of_is_tree #t (x:tree_t t) (ft:T.tree t)
120120
T.Leaf -> {
121121
unfold (is_tree x T.Leaf);
122122
fold (is_tree_cases None ft);
123+
rewrite is_tree_cases None ft as is_tree_cases x ft;
123124
}
124125
T.Node data ltree rtree -> {
125126
unfold (is_tree x (T.Node data ltree rtree));
126127
with p lct rct. _;
127128
with n. assert p |-> n;
128129
with l'. rewrite is_tree lct l' as is_tree n.left l';
129130
with r'. rewrite is_tree rct r' as is_tree n.right r';
130-
fold (is_tree_cases (Some p) (T.Node data ltree rtree))
131+
fold (is_tree_cases (Some p) ft);
132+
rewrite (is_tree_cases (Some p) ft) as is_tree_cases x ft;
131133
}
132134
}
133135
}
@@ -240,8 +242,6 @@ fn node_cons (#t:Type0) (v:t) (ltree:tree_t t) (rtree:tree_t t) (#l:(T.tree t))
240242
ensures is_tree y (T.Node v l r) ** (pure (Some? y))
241243
{
242244
let y = Box.alloc { data=v; left =ltree; right = rtree };
243-
rewrite each ltree as ({data = v; left = ltree; right = rtree}).left in (is_tree ltree l);
244-
rewrite each rtree as ({data = v; left = ltree; right = rtree}).right in (is_tree rtree r);
245245
intro_is_tree_node (Some y) y;
246246
Some y
247247
}
@@ -293,18 +293,12 @@ fn rec append_left (#t:Type0) (x:tree_t t) (v:t) (#ft:G.erased (T.tree t))
293293

294294
is_tree_case_some (Some vl) vl;
295295

296-
with _node _ltree _rtree._;
297-
298296
let node = !vl;
299297

300298
let left_new = append_left node.left v;
301299

302300
vl := {node with left = left_new};
303301

304-
rewrite each left_new as ({ node with left = left_new }).left in (is_tree left_new ((T.append_left (reveal _ltree) v)));
305-
306-
rewrite each node.right as ({ node with left = left_new }).right in (is_tree node.right _rtree);
307-
308302
intro_is_tree_node x vl;
309303

310304
x
@@ -344,18 +338,12 @@ fn rec append_right (#t:Type0) (x:tree_t t) (v:t) (#ft:G.erased (T.tree t))
344338
Some np -> {
345339
is_tree_case_some (Some np) np;
346340

347-
with _node _ltree _rtree._;
348-
349341
let node = !np;
350342

351343
let right_new = append_right node.right v;
352344

353345
np := {node with right = right_new};
354346

355-
rewrite each right_new as ({ node with right = right_new }).right in (is_tree right_new ((T.append_right (reveal _rtree) v)));
356-
357-
rewrite each node.left as ({node with right = right_new}).left in (is_tree node.left _ltree);
358-
359347
intro_is_tree_node x np;
360348

361349
x

lib/pulse/lib/Pulse.Lib.Borrow.fst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ noeq type blockchain_root = {
4141
type lifetime : Type0 =
4242
ref blockchain_root
4343

44-
let fpts_to #t (r: ref t) (x: t) = exists* p. pts_to r #p x
44+
let fpts_to #t ([@@@mkey] r: ref t) (x: t) = exists* p. pts_to r #p x
4545

4646
ghost fn dup_fpts_to u#t (t: Type u#t) r x () : duplicable_f (fpts_to #t r x) = {
4747
unfold fpts_to r x;
@@ -189,7 +189,7 @@ type stored_shape =
189189
| Stored
190190
| StoredBoth : stored_shape -> stored_shape -> stored_shape
191191

192-
let rec bc_stored ([@@@mkey] x: blockchain_edge) ([@@@mkey] d: stored_shape) (y: slprop) : Tot slprop (decreases d) =
192+
let rec bc_stored ([@@@mkey] x: blockchain_edge) (d: stored_shape) (y: slprop) : Tot slprop (decreases d) =
193193
match d with
194194
| Stored -> exists* z. slprop_ref_pts_to x.be_prop z ** later z ** trade (later z) y
195195
| StoredCheckedOut -> live x.be_ref ** y
@@ -199,15 +199,15 @@ let rec bc_stored ([@@@mkey] x: blockchain_edge) ([@@@mkey] d: stored_shape) (y:
199199
bc_stored b db yb **
200200
trade (ya ** yb) y
201201

202-
let rec rt_stored ([@@@mkey] x: ref blockchain_root) ([@@@mkey] n: unat) (b: slprop) : Tot slprop (decreases n) =
202+
let rec rt_stored ([@@@mkey] x: ref blockchain_root) (n: unat) (b: slprop) : Tot slprop (decreases n) =
203203
match n with
204204
| Zero -> trade emp b
205205
| Succ n -> exists* r (b1 b2: slprop). fpts_to x r **
206206
(exists* d. bc_stored r.rt_tree d b1) **
207207
rt_stored r.rt_next n b2 **
208208
trade (b1 ** b2) b
209209

210-
let owns_end ([@@@mkey] x: ref blockchain_root) ([@@@mkey] n: unat) =
210+
let owns_end ([@@@mkey] x: ref blockchain_root) (n: unat) =
211211
exists* y. root_idx x n y ** live y
212212

213213
ghost fn elim_owns_end_zero x
@@ -574,7 +574,7 @@ ghost fn share_borrow' #a (p q1 q2: slprop)
574574
dup (slprop_ref_pts_to eb.be_prop q2) ();
575575
fold valid_split l.be_prop ea.be_prop eb.be_prop;
576576
dup (bc_idx r.rt_tree is l) ();
577-
dup (valid_split l.be_prop ra rb) ();
577+
dup (valid_split l.be_prop ea.be_prop eb.be_prop) ();
578578
push_bc_idx r.rt_tree is false l;
579579
push_bc_idx r.rt_tree is true l;
580580
dup (root_idx' a n r) ();

lib/pulse/lib/Pulse.Lib.CancellableInvariant.fsti

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ val cinv : Type0
2525
instance val non_informative_cinv
2626
: NonInformative.non_informative cinv
2727

28-
val cinv_vp (c:cinv) (v:slprop) : slprop
28+
val cinv_vp ([@@@mkey] c:cinv) (v:slprop) : slprop
2929

30-
val active (c:cinv) (p:perm) : slprop
30+
val active ([@@@mkey] c:cinv) (p:perm) : slprop
3131

3232
val active_timeless (c:cinv) (p:perm)
3333
: Lemma (timeless (active c p))

lib/pulse/lib/Pulse.Lib.ConditionVar.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ ensures
167167
later_intro (cvar_inv b.core p);
168168
drop_ (Box.pts_to b.core.r #0.5R _)
169169
};
170-
drop_ _
170+
drop_ (inv _ _)
171171
}
172172

173173
fn signal (c:cvar_t) (#p:slprop)

lib/pulse/lib/Pulse.Lib.Deque.fst

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ type deque (t:Type0) = {
2121
tail: option (node_ptr t);
2222
}
2323

24-
(* Note: since within this module there is usually a *single* linked list
25-
around, we mark the list predicated with no_mkeys so the matcher can be
26-
more liberal. Crucially, this attribute is only set behind the interface,
27-
and clients will just use the mkey in is_deque.
28-
29-
This is a bit of a hack, the fact that F* allows the attributes to differ
30-
between fst/fsti is probably wrong. Maybe we should have a typeclass? *)
31-
32-
[@@no_mkeys]
3324
let rec is_deque_suffix
3425
(#t:Type0)
3526
([@@@mkey] p:node_ptr t)
@@ -82,7 +73,6 @@ fn fold_is_deque_suffix_cons
8273

8374

8475

85-
[@@no_mkeys]
8676
let is_deque #t ([@@@mkey] x:deque t) (l:list t)
8777
: Tot slprop (decreases l)
8878
= match l with
@@ -120,7 +110,7 @@ fn push_front_empty (#t:Type) (l : deque t) (x : t)
120110
};
121111
let node = Box.alloc vnode;
122112

123-
fold (is_deque_suffix node [x] None node);
113+
fold (is_deque_suffix node [x] None node None);
124114

125115
let l' = {
126116
head = Some node;
@@ -287,10 +277,8 @@ let is_deque_suffix_factored
287277
: Tot slprop
288278
= exists* (v:node t).
289279
pts_to x v **
290-
pure (
291-
v.value == List.Tot.hd l /\
292-
v.dprev == prev
293-
) **
280+
pure (v.value == List.Tot.hd l) **
281+
pure (v.dprev == prev) **
294282
is_deque_suffix_factored_next x l tail last v.dnext
295283

296284

@@ -655,7 +643,7 @@ fn pop_front (#t:Type) (l : deque t)
655643
{
656644
let b = is_singleton l;
657645
if b {
658-
pop_front_nil l;
646+
pop_front_nil l #x;
659647
} else {
660648
pop_front_cons l;
661649
}

lib/pulse/lib/Pulse.Lib.Forall.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn elim_forall u#a
4747
{
4848
unfold (forall* x. p x);
4949
unfold uquant (F.on_dom a (fun x -> p x));
50-
with v. assert token v; unfold token v;
50+
with v. unfold token v;
5151
extract_q v (F.on_domain a (fun x -> p x)) () x;
5252
}
5353

lib/pulse/lib/Pulse.Lib.GhostPCMReference.fst

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn read u#a
6363
returns v:(v:a { compatible p x v /\ p.refine v })
6464
ensures pts_to r (f v)
6565
{
66-
with inst. assert small_token u#a inst; let inst = inst;
66+
with inst. unfold small_token u#a inst; let inst = inst; fold small_token inst;
6767
U.downgrade_val (C.ghost_read #(U.raise_t a) #(raise p) r (hide (U.raise_val (reveal x))) (raise_refine p x f));
6868
}
6969

@@ -92,7 +92,7 @@ fn write u#a
9292
requires pts_to r x
9393
ensures pts_to r y
9494
{
95-
with inst. assert small_token u#a inst; let inst = inst;
95+
with inst. unfold small_token u#a inst; let inst = inst; fold small_token inst;
9696
C.ghost_write #(U.raise_t a) #(raise p) r (hide (U.raise_val (reveal x))) (hide (U.raise_val (reveal y)))
9797
(raise_upd f)
9898
}
@@ -107,18 +107,12 @@ fn share u#a
107107
requires pts_to r (v0 `op pcm` v1)
108108
ensures pts_to r v0 ** pts_to r v1
109109
{
110-
with inst. assert small_token u#a inst; let inst = inst;
111-
fold small_token u#a inst;
110+
with inst. unfold small_token u#a inst; let inst = inst;
111+
fold small_token inst;
112+
fold small_token inst;
112113
C.ghost_share #_ #(PR.raise pcm) r (U.raise_val v0) (U.raise_val v1)
113114
}
114115

115-
[@@allow_ambiguous]
116-
ghost fn drop_amb (p: slprop)
117-
requires p
118-
{
119-
drop_ p
120-
}
121-
122116
[@@allow_ambiguous]
123117
ghost
124118
fn gather u#a
@@ -131,11 +125,9 @@ fn gather u#a
131125
returns squash (composable pcm v0 v1)
132126
ensures pts_to r (op pcm v0 v1)
133127
{
134-
with inst. assert C.ghost_pcm_pts_to #_ #(raise #a #inst pcm) r (U.raise_val v1);
135-
with inst'. assert C.ghost_pcm_pts_to #_ #(raise #a #inst' pcm) r (U.raise_val v1);
136-
drop_amb (small_token u#a inst');
137-
let inst = inst;
138-
C.ghost_gather #_ #(PR.raise pcm) r (U.raise_val v0) (U.raise_val v1)
128+
with inst. assert C.ghost_pcm_pts_to #_ #(raise #a #inst pcm) r (U.raise_val #a #inst v1);
129+
drop_ (small_token inst);
130+
C.ghost_gather #_ #(PR.raise #a #inst pcm) r (U.raise_val #a #inst v0) (U.raise_val #a #inst v1)
139131
}
140132

141133
ghost fn pts_to_not_null u#a (#a:Type u#a)

lib/pulse/lib/Pulse.Lib.HashTable.fst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ fn delete
556556
if (voff = ht.sz)
557557
{
558558
cont := false;
559-
rewrite each vcont as false; // also relying on #110
560559
}
561560
else
562561
{
@@ -584,7 +583,6 @@ fn delete
584583
{
585584
cont := false;
586585
assert (pure (pht.repr == (PHT.delete pht k).repr));
587-
rewrite each vcont as false; // also relying on #110
588586
}
589587
Zombie ->
590588
{

lib/pulse/lib/Pulse.Lib.HashTable.fsti

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ let related #kt #vt (ht:ht_t kt vt) (pht:pht_t kt vt) : prop =
4444
SZ.v ht.sz == pht.repr.sz /\
4545
pht.repr.hashf == lift_hash_fun ht.hashf
4646

47-
let models #kt #vt (ht:ht_t kt vt) (pht:pht_t kt vt) : slprop =
47+
let models #kt #vt ([@@@mkey]ht: ht_t kt vt) (pht:pht_t kt vt) : slprop =
4848
V.pts_to ht.contents pht.repr.seq **
4949
pure (related ht pht /\
5050
V.is_full_vec ht.contents /\
5151
SZ.fits (2 `op_Multiply` SZ.v ht.sz))
5252

53-
val models_timeless #kt #vt (ht:ht_t kt vt) (pht:pht_t kt vt)
53+
val models_timeless #kt #vt ([@@@mkey] ht:ht_t kt vt) (pht:pht_t kt vt)
5454
: Lemma (timeless (models ht pht))
5555
[SMTPat (timeless (models ht pht))]
5656

0 commit comments

Comments
 (0)