Commit 103f5e8b authored by Robbert Krebbers's avatar Robbert Krebbers

New mechanism for heap_lang substitutions.

It is based on type classes and can it be tuned by providing
instances, for example, instances can be provided to mark that
certain expressions are closed.
parent d10c1878
Pipeline #179 passed with stage
From heap_lang Require Export notation.
From heap_lang Require Export substitution notation.
Definition newchan := (λ: "", ref '0)%L.
Definition signal := (λ: "x", "x" <- '1)%L.
Definition wait := (rec: "wait" "x" :=if: !"x" = '1 then '() else "wait" "x")%L.
Definition newchan : val := λ: "", ref '0.
Definition signal : val := λ: "x", "x" <- '1.
Definition wait : val :=
rec: "wait" "x" := if: !"x" = '1 then '() else "wait" "x".
Instance newchan_closed : Closed newchan. Proof. solve_closed. Qed.
Instance signal_closed : Closed signal. Proof. solve_closed. Qed.
Instance wait_closed : Closed wait. Proof. solve_closed. Qed.
\ No newline at end of file
......@@ -16,20 +16,20 @@ Implicit Types P Q : iProp heap_lang Σ.
Implicit Types Φ : val iProp heap_lang Σ.
(** Proof rules for the sugar *)
Lemma wp_lam' E x ef e v Φ :
Lemma wp_lam E x ef e v Φ :
to_val e = Some v
|| subst ef x v @ E {{ Φ }} || App (Lam x ef) e @ E {{ Φ }}.
Proof. intros. by rewrite -wp_rec' ?subst_empty. Qed.
Proof. intros. by rewrite -wp_rec ?subst_empty. Qed.
Lemma wp_let' E x e1 e2 v Φ :
Lemma wp_let E x e1 e2 v Φ :
to_val e1 = Some v
|| subst e2 x v @ E {{ Φ }} || Let x e1 e2 @ E {{ Φ }}.
Proof. apply wp_lam'. Qed.
Proof. apply wp_lam. Qed.
Lemma wp_seq E e1 e2 v Φ :
to_val e1 = Some v
|| e2 @ E {{ Φ }} || Seq e1 e2 @ E {{ Φ }}.
Proof. intros ?. rewrite -wp_let' // subst_empty //. Qed.
Proof. intros ?. rewrite -wp_let // subst_empty //. Qed.
Lemma wp_skip E Φ : Φ (LitV LitUnit) || Skip @ E {{ Φ }}.
Proof. rewrite -wp_seq // -wp_value //. Qed.
......
......@@ -84,7 +84,7 @@ Qed.
(* For the lemmas involving substitution, we only derive a preliminary version.
The final version is defined in substitution.v. *)
Lemma wp_rec' E f x e1 e2 v Φ :
Lemma wp_rec E f x e1 e2 v Φ :
to_val e2 = Some v
|| subst (subst e1 f (RecV f x e1)) x v @ E {{ Φ }}
|| App (Rec f x e1) e2 @ E {{ Φ }}.
......@@ -94,6 +94,13 @@ Proof.
intros; inv_step; eauto.
Qed.
Lemma wp_rec' E f x erec v1 e2 v2 Φ :
v1 = RecV f x erec
to_val e2 = Some v2
|| subst (subst erec f v1) x v2 @ E {{ Φ }}
|| App (of_val v1) e2 @ E {{ Φ }}.
Proof. intros ->. apply wp_rec. Qed.
Lemma wp_un_op E op l l' Φ :
un_op_eval op l = Some l'
Φ (LitV l') || UnOp op (Lit l) @ E {{ Φ }}.
......@@ -140,7 +147,7 @@ Proof.
?right_id -?wp_value //; intros; inv_step; eauto.
Qed.
Lemma wp_case_inl' E e0 v0 x1 e1 x2 e2 Φ :
Lemma wp_case_inl E e0 v0 x1 e1 x2 e2 Φ :
to_val e0 = Some v0
|| subst e1 x1 v0 @ E {{ Φ }} || Case (InjL e0) x1 e1 x2 e2 @ E {{ Φ }}.
Proof.
......@@ -148,7 +155,7 @@ Proof.
(subst e1 x1 v0) None) ?right_id //; intros; inv_step; eauto.
Qed.
Lemma wp_case_inr' E e0 v0 x1 e1 x2 e2 Φ :
Lemma wp_case_inr E e0 v0 x1 e1 x2 e2 Φ :
to_val e0 = Some v0
|| subst e2 x2 v0 @ E {{ Φ }} || Case (InjR e0) x1 e1 x2 e2 @ E {{ Φ }}.
Proof.
......
This diff is collapsed.
......@@ -48,6 +48,11 @@ Section LiftingTests.
λ: "x",
if: "x" '0 then -FindPred (-"x" + '2) '0 else FindPred "x" '0.
Instance FindPred_closed : Closed FindPred | 0.
Proof. solve_closed. Qed.
Instance Pred_closed : Closed Pred | 0.
Proof. solve_closed. Qed.
Lemma FindPred_spec n1 n2 E Φ :
n1 < n2
Φ '(n2 - 1) || FindPred 'n2 'n1 @ E {{ Φ }}.
......
From algebra Require Export upred_tactics.
From heap_lang Require Export tactics substitution.
From heap_lang Require Export tactics derived substitution.
Import uPred.
(** wp-specific helper tactics *)
......@@ -30,8 +30,9 @@ Tactic Notation "wp_rec" ">" :=
match eval cbv in e' with
| App (Rec _ _ _) _ =>
wp_bind K; etrans;
[|eapply wp_rec; repeat (reflexivity || rewrite /= to_of_val)];
wp_finish
[|first [eapply wp_rec' | eapply wp_rec];
repeat (reflexivity || rewrite /= to_of_val)];
simpl_subst; wp_finish
end)
end).
Tactic Notation "wp_rec" := wp_rec>; try strip_later.
......@@ -43,7 +44,7 @@ Tactic Notation "wp_lam" ">" :=
| App (Rec "" _ _) _ =>
wp_bind K; etrans;
[|eapply wp_lam; repeat (reflexivity || rewrite /= to_of_val)];
wp_finish
simpl_subst; wp_finish
end)
end.
Tactic Notation "wp_lam" := wp_lam>; try strip_later.
......
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