Skip to content

Commit 5b3e515

Browse files
authored
Merge pull request #488 from FStarLang/nik_univs
Fixes in anticipation of F* universes in SMT encoding
2 parents 47b4e21 + f93ceee commit 5b3e515

30 files changed

+181
-102
lines changed

lib/core/PulseCore.BaseHeapSig.fst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ let emp_unit (p:slprop) : Lemma (p == (p `star` emp)) =
8989
star_equiv p emp h
9090
);
9191
slprop_extensionality p (p `star` emp)
92-
93-
let pure_true_emp () : Lemma (pure True == emp) =
94-
introduce forall h. interp (pure True) h <==> interp emp h with H2.intro_emp h;
95-
slprop_extensionality (pure True) emp
92+
let pure_true_emp () : Lemma (pure u#a True == emp) =
93+
introduce forall h. interp (pure u#a True) h <==> interp emp h with H2.intro_emp h;
94+
slprop_extensionality (pure u#a True) emp
9695
let intro_emp (h:mem) : Lemma (interp emp h) = H2.intro_emp h
9796
let pure_interp (p:prop) (c:mem) : Lemma (interp (pure p) c == p) =
9897
H2.pure_interp p c; PropositionalExtensionality.apply (interp (pure p) c) p

lib/core/PulseCore.Heap2.fst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ let lift_star (l:tag) (p q:H.slprop)
161161
);
162162
slprop_extensionality (llift l (p `H.star` q)) (llift l p `star` llift l q)
163163
#pop-options
164-
let lift_emp : squash (lift H.emp == emp) =
165-
FStar.Classical.forall_intro H.intro_emp;
166-
slprop_extensionality (lift H.emp) emp
164+
let lift_emp : squash (lift H.emp == emp u#a) =
165+
FStar.Classical.forall_intro (H.intro_emp u#a);
166+
slprop_extensionality (lift u#a H.emp) (emp u#a)
167167

168168
let pts_to_compatible #a #pcm (x:ref a pcm) (v0 v1:a) h =
169169
H.pts_to_compatible #a #pcm x v0 v1 h.concrete;
@@ -571,9 +571,9 @@ let lift_action_ghost
571571
let ni_erased a : non_informative (erased a) = fun x -> reveal x
572572
let ni_unit : non_informative unit = fun x -> reveal x
573573

574-
let lift_ghost_emp : squash (llift GHOST H.emp == emp) =
575-
FStar.Classical.forall_intro H.intro_emp;
576-
slprop_extensionality (llift GHOST H.emp) emp
574+
let lift_ghost_emp : squash (llift GHOST H.emp == emp u#a) =
575+
FStar.Classical.forall_intro (H.intro_emp u#a);
576+
slprop_extensionality (llift GHOST H.emp) (emp u#a)
577577

578578
let core_ghost_ref_as_addr i = H.core_ref_as_addr i
579579
let core_ghost_ref_is_null c = H.core_ref_is_null c

lib/core/PulseCore.MemoryAlt.fst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ let emp_unit (p:slprop)
6060
: Lemma (p `equiv` (p `star` emp))
6161
= B.emp_unit p
6262

63+
#push-options "--print_implicits --print_universes"
64+
6365
let pure_equiv (p q:prop)
64-
: Lemma ((p <==> q) ==> (pure p `equiv` pure q))
66+
: Lemma ((p <==> q) ==> (pure u#a p `equiv` pure u#a q))
6567
= FStar.PropositionalExtensionality.apply p q
6668

6769
let pure_true_emp (_:unit)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ fn insert_if_not_full
505505
}
506506
}
507507

508+
#restart-solver
508509
#push-options "--z3rlimit_factor 6"
509510
fn delete
510511
(#[@@@ Rust_generics_bounds ["Copy"; "PartialEq"; "Clone"]] kt:eqtype)

mk/checker.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ROOTS += lib/common/Pulse.Lib.Tactics.fsti
99

1010
FSTAR_OPTIONS += --already_cached 'Prims,FStar'
1111
FSTAR_OPTIONS += --include lib/common
12+
FSTAR_OPTIONS += --smtencoding.elim_box true
13+
FSTAR_OPTIONS += --z3smtopt '(set-option :smt.arith.nl false)'
1214
EXTRACT += --extract '-*,+Pulse,+PulseSyntaxExtension'
1315
DEPFLAGS += --already_cached 'Prims,FStar,FStarC'
1416

src/checker/Pulse.Checker.AssertWithBinders.fst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ let rec add_rem_uvs (g:env) (t:typ) (uvs:env { Env.disjoint g uvs }) (v:slprop)
410410
let v = tm_pureapp v qopt (tm_var {nm_index = x; nm_ppname = ppname}) in
411411
add_rem_uvs g (comp_res ct) uvs v
412412

413+
#push-options "--fuel 0 --ifuel 0"
413414
let check
414415
(g:env)
415416
(pre:term)
@@ -424,7 +425,7 @@ let check
424425
let g = push_context g "check_assert" st.range in
425426

426427
let Tm_ProofHintWithBinders { hint_type; binders=bs; t=body } = st.term in
427-
428+
allow_invert hint_type;
428429
match hint_type with
429430
| WILD ->
430431
let st = check_wild g pre st in
@@ -543,3 +544,4 @@ let check
543544
{ t with effect_tag = st.effect_tag }
544545
in
545546
check g pre pre_typing post_hint res_ppname st
547+
#pop-options

src/checker/Pulse.Checker.Base.fst

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ let post_hint_from_comp_typing #g #c ct =
176176
in
177177
p
178178

179+
#push-options "--z3rlimit_factor 4"
179180
let comp_typing_from_post_hint
180181
(#g: env)
181182
(c: comp_st)
@@ -297,7 +298,7 @@ let comp_with_pre (c:comp_st) (pre:term) =
297298
| C_STGhost i st -> C_STGhost i { st with pre }
298299
| C_STAtomic i obs st -> C_STAtomic i obs {st with pre}
299300

300-
301+
#push-options "--fuel 0 --ifuel 0"
301302
let st_equiv_pre (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
302303
(pre:term)
303304
(veq: slprop_equiv g (comp_pre c) pre)
@@ -312,8 +313,6 @@ let st_equiv_pre (#g:env) (#t:st_term) (#c:comp_st) (d:st_typing g t c)
312313
in
313314
t_equiv d st_equiv
314315

315-
316-
#push-options "--z3rlimit_factor 4 --ifuel 2 --fuel 0"
317316
let k_elab_equiv_continuation (#g1:env) (#g2:env { g2 `env_extends` g1 }) (#ctxt #ctxt1 #ctxt2:term)
318317
(k:continuation_elaborator g1 ctxt g2 ctxt1)
319318
(d:slprop_equiv g2 ctxt1 ctxt2)
@@ -324,15 +323,13 @@ let k_elab_equiv_continuation (#g1:env) (#g2:env { g2 `env_extends` g1 }) (#ctxt
324323
assert (comp_pre c == ctxt2);
325324
let st_d' : st_typing g2 st (comp_with_pre c ctxt1) = st_equiv_pre st_d _ (VE_Sym _ _ _ d) in
326325
k post_hint (| st, _, st_d' |)
327-
#pop-options
328326

329327
let slprop_equiv_typing_fwd (#g:env) (#ctxt:_) (ctxt_typing:tot_typing g ctxt tm_slprop)
330328
(#p:_) (d:slprop_equiv g ctxt p)
331329
: tot_typing g p tm_slprop
332330
= let fwd, _ = slprop_equiv_typing d in
333331
fwd ctxt_typing
334332

335-
#push-options "--z3rlimit_factor 4 --ifuel 1 --fuel 0"
336333
let k_elab_equiv_prefix
337334
(#g1:env) (#g2:env { g2 `env_extends` g1 }) (#ctxt1 #ctxt2 #ctxt:term)
338335
(k:continuation_elaborator g1 ctxt1 g2 ctxt)
@@ -347,7 +344,6 @@ let k_elab_equiv_prefix
347344
let (| st, c, st_d |) = res in
348345
assert (comp_pre c == ctxt1);
349346
(| _, _, st_equiv_pre st_d _ d |)
350-
#pop-options
351347

352348
let k_elab_equiv
353349
(#g1:env) (#g2:env { g2 `env_extends` g1 }) (#ctxt1 #ctxt1' #ctxt2 #ctxt2':term)
@@ -362,7 +358,7 @@ let k_elab_equiv
362358
k_elab_equiv_prefix k d1 in
363359
k
364360

365-
#push-options "--fuel 3 --ifuel 2 --split_queries no --z3rlimit_factor 20"
361+
#push-options "--fuel 3 --ifuel 1 --split_queries no --z3rlimit_factor 20"
366362
open Pulse.PP
367363
let continuation_elaborator_with_bind' (#g:env) (ctxt:term)
368364
(#c1:comp{stateful_comp c1})
@@ -571,6 +567,7 @@ let emp_inames_included (g:env) (i:term) (_:tot_typing g i tm_inames)
571567
: prop_validity g (tm_inames_subset tm_emp_inames i)
572568
= RU.magic()
573569

570+
#push-options "--ifuel 1"
574571
let return_in_ctxt (g:env) (y:var) (y_ppname:ppname) (u:universe) (ty:term) (ctxt:slprop)
575572
(ty_typing:universe_of g ty u)
576573
(post_hint0:post_hint_opt g { PostHint? post_hint0 /\ checker_res_matches_post_hint g post_hint0 y ty ctxt})
@@ -614,8 +611,9 @@ let return_in_ctxt (g:env) (y:var) (y_ppname:ppname) (u:universe) (ty:term) (ctx
614611
| _ ->
615612
(| _, _, d |)
616613

617-
#push-options "--z3rlimit_factor 2"
614+
#push-options "--z3rlimit_factor 4 --ifuel 1 --split_queries always"
618615
#restart-solver
616+
#show-options
619617
let match_comp_res_with_post_hint (#g:env) (#t:st_term) (#c:comp_st)
620618
(d:st_typing g t c)
621619
(post_hint:post_hint_opt g)
@@ -651,6 +649,7 @@ let match_comp_res_with_post_hint (#g:env) (#t:st_term) (#c:comp_st)
651649

652650
(| t, c', Pulse.Typing.Combinators.t_equiv d d_stequiv |)
653651
#pop-options
652+
#pop-options
654653

655654
let apply_checker_result_k (#g:env) (#ctxt:slprop) (#post_hint:post_hint_for_env g)
656655
(r:checker_result_t g ctxt (PostHint post_hint))
@@ -667,7 +666,7 @@ let apply_checker_result_k (#g:env) (#ctxt:slprop) (#post_hint:post_hint_for_env
667666

668667
k (PostHint post_hint) d
669668

670-
#push-options "--z3rlimit_factor 4 --fuel 0 --ifuel 1"
669+
#push-options "--z3rlimit_factor 4 --fuel 0 --ifuel 0"
671670
//TODO: refactor and merge with continuation_elaborator_with_bind
672671
let checker_result_for_st_typing (#g:env) (#ctxt:slprop) (#post_hint:post_hint_opt g)
673672
(d:st_typing_in_ctxt g ctxt post_hint)
@@ -723,6 +722,7 @@ let readback_comp_res_as_comp (c:T.comp) : option comp =
723722
)
724723
| _ -> None
725724

725+
#push-options "--ifuel 1"
726726
let rec is_stateful_arrow (g:env) (c:option comp) (args:list T.argv) (out:list T.argv)
727727
: T.Tac (option (list T.argv & T.argv))
728728
= let open R in
@@ -779,6 +779,7 @@ let rec is_stateful_arrow (g:env) (c:option comp) (args:list T.argv) (out:list T
779779
)
780780
else None
781781
)
782+
#pop-options
782783

783784
let checker_result_t_equiv_ctxt (g:env) (ctxt ctxt' : slprop)
784785
(post_hint:post_hint_opt g)
@@ -796,14 +797,17 @@ let is_stateful_application (g:env) (e:term)
796797
: T.Tac (option st_term) =
797798
RU.record_stats "Pulse.is_stateful_application" fun _ ->
798799
let head, args = T.collect_app_ln e in
799-
if Nil? args then None else
800-
match RU.tc_term_phase1 (elab_env g) head false with
801-
| None, _ -> None
802-
| Some (_, ht, _), _ ->
803-
let head_t = wr ht (T.range_of_term ht) in
804-
match is_stateful_arrow g (Some (C_Tot head_t)) args [] with
805-
| None -> None
806-
| Some _ -> Some (as_stateful_application e head args)
800+
match args with
801+
| _ :: _ -> (
802+
match RU.tc_term_phase1 (elab_env g) head false with
803+
| None, _ -> None
804+
| Some (_, ht, _), _ ->
805+
let head_t = wr ht (T.range_of_term ht) in
806+
match is_stateful_arrow g (Some (C_Tot head_t)) args [] with
807+
| None -> None
808+
| Some _ -> Some (as_stateful_application e head args)
809+
)
810+
| _ -> None
807811

808812
let apply_conversion
809813
(#g:env) (#e:term) (#eff:_) (#t0:term)
@@ -888,6 +892,7 @@ let norm_st_typing_inverse
888892

889893
open FStar.List.Tot
890894
module RT = FStar.Reflection.Typing
895+
#push-options "--ifuel 1"
891896
let decompose_app (g:env) (tt:either term st_term)
892897
: T.Tac (option (term & list T.argv & (args:list T.argv{ Cons? args } -> T.Tac (res:either term st_term { Inr? tt ==> Inr? res }))))
893898
= let decompose_st_app (t:st_term)
@@ -919,6 +924,7 @@ let decompose_app (g:env) (tt:either term st_term)
919924
Some (head, args, rebuild)
920925
)
921926
| Inr st -> decompose_st_app st
927+
#pop-options
922928

923929
let anf_binder name = T.pack (T.Tv_FVar (T.pack_fv (Pulse.Reflection.Util.mk_pulse_lib_core_lid (Printf.sprintf "__%s_binder__" name))))
924930

@@ -958,11 +964,14 @@ let rec maybe_hoist (g:env) (arg:T.argv)
958964
)
959965
| Some _ -> (
960966
let g, binders, args = maybe_hoist_args g args in
961-
if Nil? args then T.fail "Impossible";
962-
let st_app = as_stateful_application t head args in
963-
let g, b, x, t = bind_st_term g st_app in
964-
let arg = t, q in
965-
g, binders@[b, x, st_app], arg
967+
if Cons? args
968+
then (
969+
let st_app = as_stateful_application t head args in
970+
let g, b, x, t = bind_st_term g st_app in
971+
let arg = t, q in
972+
g, binders@[b, x, st_app], arg
973+
)
974+
else T.fail "Impossible: is_stateful_application returned true but no args to hoist"
966975
)
967976

968977
and maybe_hoist_args (g:env) (args:list T.argv)
@@ -975,6 +984,7 @@ and maybe_hoist_args (g:env) (args:list T.argv)
975984
args
976985
(g, [], [])
977986

987+
#push-options "--ifuel 1"
978988
let maybe_hoist_top
979989
(hoist_top_level:bool)
980990
(g:env)

src/checker/Pulse.Checker.Bind.fst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Metatheory = Pulse.Typing.Metatheory
3131
module Abs = Pulse.Checker.Abs
3232
module RU = Pulse.Reflection.Util
3333

34-
#push-options "--z3rlimit_factor 4 --split_queries no"
34+
#push-options "--z3rlimit_factor 8 --split_queries no --query_stats --fuel 0 --ifuel 1"
3535
let check_bind_fn
3636
(g:env)
3737
(ctxt:slprop)
@@ -62,7 +62,6 @@ let check_bind_fn
6262
checker_result_for_st_typing d res_ppname
6363
)
6464
| _ -> fail g (Some t.range) "check_bind_fn: head is not an abstraction"
65-
#pop-options
6665

6766
let check_if_seq_lhs
6867
(g:env) (ctxt : slprop) (post_hint : post_hint_opt g)
@@ -226,4 +225,5 @@ let check_tot_bind
226225
Printf.sprintf "Elaborated and proceeding back to top-level\n%s\nto\n%s\n"
227226
(show t)
228227
(show t'));
229-
check g pre pre_typing post_hint res_ppname t'
228+
check g pre pre_typing post_hint res_ppname t'
229+
#pop-options

src/checker/Pulse.Checker.If.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let retype_checker_result (#g:env) (#ctxt:slprop) (#ph:post_hint_opt g) (ph':pos
4343
= let (| x, g1, t, ctxt, k |) = r in
4444
(| x, g1, t, ctxt, k |)
4545

46-
#push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 2"
46+
#push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2"
4747
#restart-solver
4848
let check
4949
(g:env)

src/checker/Pulse.Checker.Match.fst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ let lemma_map_opt_dec_index (top:'z) (f : (x:'a{x << top}) -> option 'b) (xs : l
139139
(ensures forall i. f (xs `L.index` i) == Some (ys `L.index` i))
140140
= Classical.forall_intro (Classical.move_requires (__lemma_map_opt_dec_index top f xs ys))
141141

142+
#push-options "--fuel 2 --ifuel 2 --z3rlimit_factor 2 --query_stats"
143+
#restart-solver
142144
let rec elab_readback_pat_x (rp : R.pattern) (p : pattern)
143145
: Lemma (requires readback_pat rp == Some p)
144146
(ensures elab_pat p == rp)
@@ -195,6 +197,7 @@ and elab_readback_subpat (pb : R.pattern & bool)
195197
(ensures elab_sub_pat (Some?.v (readback_sub_pat pb)) == pb)
196198
= let (p, b) = pb in
197199
elab_readback_pat_x p (Some?.v (readback_pat p))
200+
#pop-options
198201

199202
val tot_typing_weakening_n
200203
(#g:env) (#t:term) (#ty:term)
@@ -236,8 +239,8 @@ let rec bindings_to_string (bs : list binding) : T.Tac string =
236239
| b::bs ->
237240
(string_of_int (fst b) ^ ":" ^ Pulse.Syntax.Printer.term_to_string (snd b) ^ " ") ^ bindings_to_string bs
238241

239-
#push-options "--z3rlimit 20"
240-
242+
#push-options "--z3rlimit 40 --fuel 0 --ifuel 1"
243+
#restart-solver
241244
let check_branch
242245
(norw:bool)
243246
(g:env)
@@ -437,7 +440,7 @@ let rec least_tag (#g #pre #post_hint #sc_u #sc_ty #sc:_)
437440
| C_STAtomic i _ _ -> STT_Atomic
438441

439442

440-
#push-options "--z3rlimit_factor 4 --fuel 0 --ifuel 1"
443+
#push-options "--z3rlimit_factor 4 --fuel 0 --ifuel 0"
441444
#restart-solver
442445
let weaken_branch_tag_to
443446
(#g #pre #post_hint #sc_u #sc_ty #sc:_)
@@ -448,6 +451,7 @@ let weaken_branch_tag_to
448451
if ctag_of_comp_st c = ct then br
449452
else
450453
let r = pe.e.range in
454+
allow_invert ct; allow_invert c;
451455
match ct, c with
452456
| STT_Ghost, C_STAtomic _ _ _
453457
| STT_Ghost, C_ST _ -> T.fail "Unexpected least effect"
@@ -464,6 +468,7 @@ let weaken_branch_tag_to
464468
let d = TBRV g sc_u sc_ty sc _ p e bs pf1 pf2 pf3 h d in
465469
(| pe, _, d |)
466470
)
471+
467472

468473

469474
let weaken_branch_tags
@@ -473,7 +478,9 @@ let weaken_branch_tags
473478
= let ct = least_tag checked_brs in
474479
let brs = T.map (weaken_branch_tag_to ct) checked_brs in
475480
(| ct, brs |)
481+
#pop-options
476482

483+
#push-options "--z3rlimit_factor 4 --fuel 0 --ifuel 1"
477484
let maybe_weaken_branch_tags
478485
(#g #pre #post_hint #sc_u #sc_ty #sc:_)
479486
(checked_brs : list (check_branches_aux_t #g pre post_hint sc_u sc_ty sc))
@@ -531,7 +538,7 @@ let check_branches
531538
let brs = List.Tot.map dfst checked_brs in
532539
let d : brs_typing g sc_u sc_ty sc brs c0 = check_branches_aux2 g sc_u sc_ty sc c0 checked_brs in
533540
(| brs, c0, d |)
534-
541+
#push-options "--fuel 0 --ifuel 1 --z3rlimit_factor 4 --query_stats"
535542
let check
536543
(g:env)
537544
(pre:term)
@@ -598,3 +605,4 @@ let check
598605
let c_typing = comp_typing_from_post_hint c pre_typing post_hint in
599606
let d = T_Match g sc_u sc_ty sc sc_ty_typing sc_typing c (E c_typing) brs brs_d complete_d in
600607
checker_result_for_st_typing (| _, _, d |) res_ppname
608+
#pop-options

0 commit comments

Comments
 (0)