Skip to content

Commit ae50550

Browse files
committed
Support purification inside rewrite each.
1 parent 9f07a97 commit ae50550

9 files changed

+25
-11
lines changed

src/checker/Pulse.Checker.AssertWithBinders.fst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ let rec as_subst (p : list (term & term))
264264

265265

266266

267-
let rewrite_all (is_source:bool) (g:env) (p: list (term & term)) (t:term) tac_opt : T.Tac (term & term) =
267+
let rewrite_all (is_source:bool) (g:env) (p: list (term & term)) (t:term) pre elaborated tac_opt : T.Tac (term & term) =
268268
(* We only use the rewrites_to substitution if there is no tactic attached to the
269269
rewrite. Otherwise, tactics may become brittle as the goal is changed unexpectedly
270270
by other things in the context. See tests/Match.fst. *)
@@ -275,7 +275,10 @@ let rewrite_all (is_source:bool) (g:env) (p: list (term & term)) (t:term) tac_op
275275
let t = dfst <| Pulse.Checker.Prover.normalize_slprop g t use_rwr in
276276
t
277277
in
278+
let maybe_purify t = if elaborated then t else purify_term g {ctxt_now=pre;ctxt_old=None} t in
278279
let elab_pair (lhs rhs : R.term) : T.Tac (R.term & R.term) =
280+
let lhs = maybe_purify lhs in
281+
let rhs = maybe_purify rhs in
279282
let lhs, lhs_typ = Pulse.Checker.Pure.instantiate_term_implicits g lhs None true in
280283
let rhs, rhs_typ = Pulse.Checker.Pure.instantiate_term_implicits g rhs (Some lhs_typ) true in
281284
let lhs = norm lhs in
@@ -304,7 +307,7 @@ let check_renaming
304307
})
305308
: T.Tac st_term
306309
= let Tm_ProofHintWithBinders ht = st.term in
307-
let { hint_type=RENAME { pairs; goal; tac_opt }; binders=bs; t=body } = ht in
310+
let { hint_type=RENAME { pairs; goal; tac_opt; elaborated }; binders=bs; t=body } = ht in
308311
match bs, goal with
309312
| _::_, None ->
310313
//if there are binders, we must have a goal
@@ -324,7 +327,7 @@ let check_renaming
324327

325328
| [], None ->
326329
// if there is no goal, take the goal to be the full current pre
327-
let lhs, rhs = rewrite_all (T.unseal st.source) g pairs pre tac_opt in
330+
let lhs, rhs = rewrite_all (T.unseal st.source) g pairs pre pre elaborated tac_opt in
328331
let t = { st with term = Tm_Rewrite { t1 = lhs; t2 = rhs; tac_opt; elaborated = true };
329332
source = Sealed.seal false; } in
330333
{ st with
@@ -334,7 +337,7 @@ let check_renaming
334337

335338
| [], Some goal -> (
336339
let goal, _ = PC.instantiate_term_implicits g goal None false in
337-
let lhs, rhs = rewrite_all (T.unseal st.source) g pairs goal tac_opt in
340+
let lhs, rhs = rewrite_all (T.unseal st.source) g pairs goal pre elaborated tac_opt in
338341
let t = { st with term = Tm_Rewrite { t1 = lhs; t2 = rhs; tac_opt; elaborated = true };
339342
source = Sealed.seal false; } in
340343
{ st with term = Tm_Bind { binder = as_binder tm_unit; head = t; body };

src/checker/Pulse.Checker.If.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ let check
7777
let t =
7878
mk_term (Tm_ProofHintWithBinders {
7979
binders = [];
80-
hint_type = RENAME { pairs = [(b, eq_v)]; goal=None; tac_opt=None; };
80+
hint_type = RENAME { pairs = [(b, eq_v)]; goal=None; tac_opt=None; elaborated=true };
8181
t = br;
8282
}) br.range
8383
in

src/checker/Pulse.Checker.Match.fst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ let check_branch
286286
binders = [];
287287
hint_type = RENAME { pairs = [(sc, elab_p_tm)];
288288
goal = None;
289-
tac_opt = Some Pulse.Reflection.Util.match_rewrite_tac_tm; };
289+
tac_opt = Some Pulse.Reflection.Util.match_rewrite_tac_tm;
290+
elaborated = true };
290291
t = e; })
291292
e.range
292293
in

src/checker/Pulse.Syntax.Base.fst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ let eq_hint_type (ht1 ht2:proof_hint_type)
150150
| UNFOLD { names=ns1; p=p1}, UNFOLD { names=ns2; p=p2 } ->
151151
eq_opt (eq_list (fun n1 n2 -> n1 = n2)) ns1 ns2 &&
152152
eq_tm p1 p2
153-
| RENAME { pairs=ps1; goal=p1; tac_opt=t1 }, RENAME { pairs=ps2; goal=p2; tac_opt=t2 } ->
153+
| RENAME { pairs=ps1; goal=p1; tac_opt=t1; elaborated=e1 }, RENAME { pairs=ps2; goal=p2; tac_opt=t2; elaborated=e2 } ->
154154
eq_list (fun (x1, y1) (x2, y2) -> eq_tm x1 x2 && eq_tm y1 y2) ps1 ps2 &&
155155
eq_opt eq_tm p1 p2 &&
156-
eq_tm_opt t1 t2
156+
eq_tm_opt t1 t2 &&
157+
e1 = e2
157158
| REWRITE { t1; t2; tac_opt; elaborated=e1 }, REWRITE { t1=s1; t2=s2; tac_opt=tac_opt2; elaborated=e2 } ->
158159
eq_tm t1 s1 &&
159160
eq_tm t2 s2 &&

src/checker/Pulse.Syntax.Base.fsti

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ type proof_hint_type =
179179
pairs:list (term & term);
180180
goal: option term;
181181
tac_opt : option term; (* optional tactic *)
182+
elaborated: bool; (* internally created by the checker, don't purify *)
182183
}
183184
| REWRITE {
184185
t1:slprop;

src/checker/Pulse.Syntax.Builder.fst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let tm_assert_with_binders bs p t = Tm_ProofHintWithBinders { hint_type=ASSERT {
6060
let mk_assert_hint_type p = ASSERT { p; elaborated=false }
6161
let mk_unfold_hint_type names p = UNFOLD { names; p }
6262
let mk_fold_hint_type names p = FOLD { names; p }
63-
let mk_rename_hint_type pairs goal tac_opt = RENAME { pairs; goal; tac_opt=map_opt tac_opt thunk }
63+
let mk_rename_hint_type pairs goal tac_opt = RENAME { pairs; goal; tac_opt=map_opt tac_opt thunk; elaborated=false }
6464
let mk_rewrite_hint_type t1 t2 tac_opt = REWRITE { t1; t2; tac_opt=map_opt tac_opt thunk; elaborated=false }
6565
let mk_fn_defn id isrec us bs comp meas body : decl' = FnDefn { id; isrec; us; bs; comp; meas; body }
6666
let mk_fn_decl id us bs comp : decl' = FnDecl { id; us; bs; comp; }

src/checker/Pulse.Syntax.Naming.fsti

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,11 @@ let subst_proof_hint (ht:proof_hint_type) (ss:subst)
470470
| ASSERT { p; elaborated } -> ASSERT { p=subst_term p ss; elaborated }
471471
| UNFOLD { names; p } -> UNFOLD {names; p=subst_term p ss}
472472
| FOLD { names; p } -> FOLD { names; p=subst_term p ss }
473-
| RENAME { pairs; goal; tac_opt } ->
473+
| RENAME { pairs; goal; tac_opt; elaborated } ->
474474
RENAME { pairs=subst_term_pairs pairs ss;
475475
goal=subst_term_opt goal ss;
476476
tac_opt=subst_term_opt tac_opt ss;
477+
elaborated;
477478
}
478479
| REWRITE { t1; t2; tac_opt; elaborated } ->
479480
REWRITE { t1=subst_term t1 ss;

src/ml/PulseSyntaxExtension_SyntaxWrapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ let tm_abs (b:binder)
125125
(body:st_term)
126126
r
127127
: st_term
128-
= let asc = { annotated = c; elaborated2 = None } in
128+
= let asc = { annotated = c; elaborated3 = None } in
129129
PSB.(with_range (tm_abs b q asc body) r)
130130

131131
let tm_st (head:term) (args:st_term list) r : st_term =

test/ImpureSpec.fst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,11 @@ fn test13 ()
120120
let mut y = x;
121121
fold p13 (!y);
122122
unfold p13 (!y);
123+
}
124+
125+
fn test14 ()
126+
{
127+
let mut x = 42;
128+
assert live x ** pure (!x == 42);
129+
rewrite each !x as 42;
123130
}

0 commit comments

Comments
 (0)