Commit f04307a4 authored by Robbert's avatar Robbert

Merge branch 'robbert/iEval' into 'master'

`iEval  ... in ...` for performing a tactic in an invidual proofmode hypothesis

Closes #116

See merge request FP/iris-coq!105
parents 1017fabb f5a3065b
Pipeline #6389 passed with stages
in 9 minutes and 26 seconds
......@@ -150,11 +150,22 @@ Induction
variables `x1 ... xn`, the hypotheses given by the selection pattern `selpat`,
and the spatial context.
Rewriting
---------
Rewriting / simplification
--------------------------
- `iRewrite pm_trm` / `iRewrite pm_trm in "H"` : rewrite using an internal
equality in the proof mode goal / hypothesis `H`.
- `iEval (tac)` / `iEval (tac) in H` : performs a tactic `tac` on the proof mode
goal / hypothesis `H`. The tactic `tac` should be a reduction or rewriting
tactic like `simpl`, `cbv`, `lazy`, `rewrite` or `setoid_rewrite`. The `iEval`
tactic is implemented by running `tac` on `?evar ⊢ P` / `P ⊢ ?evar` where `P`
is the proof goal / hypothesis `H`. After running `tac`, `?evar` is unified
with the resulting `P`, which in turn becomes the new proof mode goal /
hypothesis `H`.
Note that parentheses around `tac` are needed.
- `iSimpl` / `iSimpl in H` : performs `simpl` on the proof mode goal /
hypothesis `H`. This is a shorthand for `iEval (simpl)`.
- `iRewrite pm_trm` : rewrite an equality in the conclusion.
- `iRewrite pm_trm in "H"` : rewrite an equality in the hypothesis `H`.
Iris
----
......
......@@ -209,7 +209,7 @@ Lemma box_fill E f P :
Proof.
iIntros (?) "H HP"; iDestruct "H" as (Φ) "[#HeqP Hf]".
iExists Φ; iSplitR; first by rewrite big_opM_fmap.
rewrite internal_eq_iff later_iff big_opM_commute.
iEval (rewrite internal_eq_iff later_iff big_opM_commute) in "HeqP".
iDestruct ("HeqP" with "HP") as "HP".
iCombine "Hf" "HP" as "Hf".
rewrite -big_opM_opM big_opM_fmap; iApply (fupd_big_sepM _ _ f).
......
......@@ -6,18 +6,20 @@ Set Default Proof Using "Type".
Import uPred.
Lemma tac_wp_expr_eval `{heapG Σ} Δ s E Φ e e' :
e = e'
( (e'':=e'), e = e'')
envs_entails Δ (WP e' @ s; E {{ Φ }}) envs_entails Δ (WP e @ s; E {{ Φ }}).
Proof. by intros ->. Qed.
Lemma tac_twp_expr_eval `{heapG Σ} Δ s E Φ e e' :
e = e'
( (e'':=e'), e = e'')
envs_entails Δ (WP e' @ s; E [{ Φ }]) envs_entails Δ (WP e @ s; E [{ Φ }]).
Proof. by intros ->. Qed.
Tactic Notation "wp_expr_eval" tactic(t) :=
try iStartProof;
try (first [eapply tac_wp_expr_eval|eapply tac_twp_expr_eval];
[t; reflexivity|]).
try (
iStartProof;
first [eapply tac_wp_expr_eval|eapply tac_twp_expr_eval];
[let x := fresh in intros x; t; unfold x; reflexivity
|]).
Ltac wp_expr_simpl := wp_expr_eval simpl.
Ltac wp_expr_simpl_subst := wp_expr_eval simpl_subst.
......
......@@ -414,9 +414,22 @@ Qed.
(** * Basic rules *)
Lemma tac_eval Δ Q Q' :
Q = Q'
( (Q'':=Q'), Q'' Q) (* We introduce [Q''] as a let binding so that
tactics like `reflexivity` as called by [rewrite //] do not eagerly unify
it with [Q]. See [test_iEval] in [tests/proofmode]. *)
envs_entails Δ Q' envs_entails Δ Q.
Proof. by intros ->. Qed.
Proof. by intros <-. Qed.
Lemma tac_eval_in Δ Δ' i p P P' Q :
envs_lookup i Δ = Some (p, P)
( (P'':=P'), P P')
envs_simple_replace i p (Esnoc Enil i P') Δ = Some Δ'
envs_entails Δ' Q envs_entails Δ Q.
Proof.
rewrite /envs_entails. intros ? HP ? <-.
rewrite envs_simple_replace_sound //; simpl.
by rewrite HP right_id wand_elim_r.
Qed.
Lemma tac_assumption Δ i p P Q :
envs_lookup i Δ = Some (p,P) FromAssumption p P Q
......
......@@ -82,10 +82,28 @@ Ltac iStartProof :=
(** * Simplification *)
Tactic Notation "iEval" tactic(t) :=
try iStartProof;
try (eapply tac_eval; [t; reflexivity|]).
iStartProof;
eapply tac_eval;
[let x := fresh in intros x; t; unfold x; reflexivity|].
Tactic Notation "iEval" tactic(t) "in" constr(H) :=
iStartProof;
eapply tac_eval_in with _ H _ _ _;
[env_reflexivity || fail "iEval:" H "not found"
|let x := fresh in intros x; t; unfold x; reflexivity
|env_reflexivity
|].
Tactic Notation "iSimpl" := iEval simpl.
Tactic Notation "iSimpl" "in" constr(H) := iEval simpl in H.
(* It would be nice to also have an `iSsrRewrite`, however, for this we need to
pass arguments to Ssreflect's `rewrite` like `/= foo /bar` in Ltac, see:
https://sympa.inria.fr/sympa/arc/coq-club/2018-01/msg00000.html
PMP told me (= Robbert) in person that this is not possible today, but may be
possible in Ltac2. *)
(** * Context manipulation *)
Tactic Notation "iRename" constr(H1) "into" constr(H2) :=
......
......@@ -285,6 +285,13 @@ Proof. iIntros "H". iNext. by iNext. Qed.
Lemma test_iNext_laterN_laterN P n1 n2 : ^n1 ^n2 P ^n1 ^n2 P.
Proof. iIntros "H". iNext. iNext. by iNext. Qed.
Lemma test_iEval x y : (y + x)%nat = 1 - S (x + y) = 2%nat : uPred M.
Proof.
iIntros (H).
iEval (rewrite (Nat.add_comm x y) // H).
done.
Qed.
(* TODO: This test is broken in Coq 8.6. Should be restored once we drop Coq
8.6 support. See also issue #108. *)
(*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment