Skip to content

Commit efae029

Browse files
authored
Merge pull request #235 from FStarLang/gebner_gensym
Use gensym from F*
2 parents 330ab36 + 5c210b9 commit efae029

26 files changed

+806
-753
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Bug234
2+
#lang-pulse
3+
open Pulse
4+
5+
type a =
6+
type b =
7+
type c =
8+
type d =
9+
type f =
10+
11+
let ok (x:a) (y:b) (z:c) (w:d) (u:f) : slprop =
12+
emp
13+
14+
let ty (x:a) (y:b) (z:c) (w:d) = u:f -> stt unit emp (fun r -> ok x y z w u)
15+
16+
fn foo x y z w : ty x y z w = u {
17+
fold ok x y z w u;
18+
}

src/checker/Pulse.Checker.Base.fst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ let st_equiv_post (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
285285
slprop_equiv (push_binding g x ppname_default (comp_res c))
286286
(open_term (comp_post c) x)
287287
(open_term post x)))
288-
: st_typing g t (comp_st_with_post c post)
288+
: Dv (st_typing g t (comp_st_with_post c post))
289289
= if eq_tm post (comp_post c) then d
290290
else
291291
let c' = comp_st_with_post c post in
@@ -298,7 +298,7 @@ let st_equiv_post (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
298298

299299
let simplify_post (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
300300
(post:term { comp_post c == tm_star post tm_emp})
301-
: st_typing g t (comp_st_with_post c post)
301+
: Dv (st_typing g t (comp_st_with_post c post))
302302
= st_equiv_post d post (fun x -> ve_unit_r (push_binding g x ppname_default (comp_res c)) (open_term post x))
303303

304304
let simplify_lemma (c:comp_st) (c':comp_st) (post_hint:option post_hint_t)
@@ -329,7 +329,7 @@ let comp_with_pre (c:comp_st) (pre:term) =
329329
let st_equiv_pre (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
330330
(pre:term)
331331
(veq: slprop_equiv g (comp_pre c) pre)
332-
: st_typing g t (comp_with_pre c pre)
332+
: Dv (st_typing g t (comp_with_pre c pre))
333333
= if eq_tm pre (comp_pre c) then d
334334
else
335335
let c' = comp_with_pre c pre in
@@ -476,7 +476,7 @@ let st_comp_typing_with_post_hint
476476
(ctxt_typing:tot_typing g ctxt tm_slprop)
477477
(post_hint:post_hint_opt g { Some? post_hint })
478478
(c:comp_st { comp_pre c == ctxt /\ comp_post_matches_hint c post_hint })
479-
: st_comp_typing g (st_comp_of_comp c)
479+
: Dv (st_comp_typing g (st_comp_of_comp c))
480480
= let st = st_comp_of_comp c in
481481
let Some ph = post_hint in
482482
let post_typing_src
@@ -582,7 +582,7 @@ let emp_inames_included (g:env) (i:term) (_:tot_typing g i tm_inames)
582582
let return_in_ctxt (g:env) (y:var) (y_ppname:ppname) (u:universe) (ty:term) (ctxt:slprop)
583583
(ty_typing:universe_of g ty u)
584584
(post_hint0:post_hint_opt g { Some? post_hint0 /\ checker_res_matches_post_hint g post_hint0 y ty ctxt})
585-
: Pure (st_typing_in_ctxt g ctxt post_hint0)
585+
: Div (st_typing_in_ctxt g ctxt post_hint0)
586586
(requires lookup g y == Some ty)
587587
(ensures fun _ -> True)
588588
= let Some post_hint = post_hint0 in

src/checker/Pulse.Checker.Exists.fst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ let check_intro_exists
123123
let Tm_ExistsSL u b p = tv in
124124

125125
Pulse.Typing.FV.tot_typing_freevars t_typing;
126-
let ty_typing, _ = Metatheory.tm_exists_inversion #g #u #b.binder_ty #p t_typing (fresh g) in
126+
let x = fresh g in
127+
let ty_typing, _ = Metatheory.tm_exists_inversion #g #u #b.binder_ty #p t_typing x in
127128
let (| witness, witness_typing |) =
128129
check_term g witness T.E_Ghost b.binder_ty in
129130
let d = T_IntroExists g u b p witness ty_typing t_typing witness_typing in

src/checker/Pulse.Checker.STApp.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let canon_comp_eq_res (g:env) (c:comp_st)
4444
#pop-options
4545

4646
let canonicalize_st_typing (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
47-
: st_typing g t (canon_comp c)
47+
: Dv (st_typing g t (canon_comp c))
4848
= let c' = canon_comp c in
4949
let x = fresh g in
5050
assume ( ~(x `Set.mem` freevars (comp_post c)) /\

src/checker/Pulse.Checker.While.fst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ module RU = Pulse.RuntimeUtils
2929

3030
let while_cond_comp_typing (#g:env) (u:universe) (x:ppname) (ty:term) (inv_body:term)
3131
(inv_typing:tot_typing g (tm_exists_sl u (as_binder ty) inv_body) tm_slprop)
32-
: comp_typing_u g (comp_while_cond x inv_body)
32+
: Dv (comp_typing_u g (comp_while_cond x inv_body))
3333
= Metatheory.admit_comp_typing g (comp_while_cond x inv_body)
3434

3535
let while_body_comp_typing (#g:env) (u:universe) (x:ppname) (ty:term) (inv_body:term)
3636
(inv_typing:tot_typing g (tm_exists_sl u (as_binder ty) inv_body) tm_slprop)
37-
: comp_typing_u g (comp_while_body x inv_body)
37+
: Dv (comp_typing_u g (comp_while_body x inv_body))
3838
= Metatheory.admit_comp_typing g (comp_while_body x inv_body)
3939

4040
#push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 4"

src/checker/Pulse.RuntimeUtils.fsti

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ val print_context (c:context) : T.Tac string
2727
val debug_at_level_no_module (s:string) : bool
2828
val debug_at_level (g:env) (s:string) : bool
2929
val print_exn (e:exn) : string
30+
val next_id () : Dv nat
3031
val bv_set_range (x:bv) (r:range) : b:bv{b==x}
3132
val bv_range (x:bv) : range
3233
val binder_set_range (x:binder) (r:range) : b:binder{b==x}

src/checker/Pulse.Typing.Combinators.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ let apply_frame (#g:env)
458458
(#c:comp { stateful_comp c })
459459
(t_typing: st_typing g t c)
460460
(frame_t:frame_for_req_in_ctxt g ctxt (comp_pre c))
461-
: Tot (c':comp_st { comp_pre c' == ctxt /\
461+
: Dv (c':comp_st { comp_pre c' == ctxt /\
462462
comp_res c' == comp_res c /\
463463
comp_u c' == comp_u c /\
464464
comp_post c' == tm_star (comp_post c) (frame_of frame_t) } &

src/checker/Pulse.Typing.Combinators.fsti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ val apply_frame (#g:env)
9393
(#c:comp { stateful_comp c })
9494
(t_typing: st_typing g t c)
9595
(frame_t:frame_for_req_in_ctxt g ctxt (comp_pre c))
96-
: Tot (c':comp_st { comp_pre c' == ctxt /\
96+
: Dv (c':comp_st { comp_pre c' == ctxt /\
9797
comp_res c' == comp_res c /\
9898
comp_u c' == comp_u c /\
9999
comp_post c' == tm_star (comp_post c) (frame_of frame_t) } &

src/checker/Pulse.Typing.Env.fst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,10 @@ let push_binding_bs _ _ _ _ = ()
9696

9797
let push_binding_as_map _ _ _ _ = ()
9898

99-
let rec max (bs:list (var & typ)) (current:var)
100-
: v:var { current <= v /\ (forall (b:var & typ). List.Tot.memP b bs ==> fst b <= v) } =
101-
match bs with
102-
| [] -> current
103-
| (x, t)::rest ->
104-
let current = if x < current then current else x in
105-
max rest current
106-
10799
let fresh g =
108-
match g.bs with
109-
| [] -> 1
110-
| (x, _)::bs_rest ->
111-
let max = max bs_rest x in
112-
max + 1
100+
let v = RU.next_id () in
101+
assume ~(v `Set.mem` dom g);
102+
v
113103

114104
//
115105
// TODO: Move to ulib

src/checker/Pulse.Typing.Env.fsti

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ let lookup (g:env) (x:var) : option typ =
9393
let m = as_map g in
9494
if Map.contains m x then Some (Map.sel m x) else None
9595

96-
val fresh (g:env) : v:var { ~ (Set.mem v (dom g)) }
96+
val fresh (g:env) : Dv (v:var { ~ (Set.mem v (dom g)) })
9797

9898
let contains (g:env) (x:var) = Map.contains (as_map g) x
9999

0 commit comments

Comments
 (0)