Commit 865b1f14 by Robbert Krebbers

### Merge branch 'master' of gitlab.science.ru.nl:lgg/iris-c-monad

parents f612cffc af8c5367
 ... ... @@ -44,16 +44,16 @@ Notation "e1 ;;;; e2" := (a_seq_bind e1 (λ: <>, e2))%E (at level 80, right associativity). Definition a_if : val := λ: "cnd" "e1" "e2", a_bind (λ: "c", if: "c" then "e1" else "e2") "cnd". a_bind (λ: "c", if: "c" then "e1" #() else "e2" #()) "cnd". Definition a_while: val := rec: "while" "cnd" "bdy" := a_if "cnd" ("bdy" ;;;; "while" "cnd" "bdy") (a_ret #()). a_if ("cnd" #()) ("bdy" ;;;; "while" "cnd" "bdy"). Section proofs. Context `{locking_heapG Σ, heapG Σ, flockG Σ, spawnG Σ}. Lemma a_seq_spec R Φ : Lemma a_seq_spec R Φ : U (Φ #()) -∗ awp (a_seq #()) R Φ. Proof. ... ... @@ -98,17 +98,17 @@ Section proofs. iModIntro. by awp_lam. Qed. Lemma a_load_spec R (l : loc) (v : val) Φ : l ↦U v -∗ (l ↦U v -∗ Φ v) -∗ awp (a_load (a_ret #l)) R Φ. Lemma a_load_spec R Φ Ψ e : awp e R (λ v, ∃ l : loc, ⌜v = #l⌝ ∧ Ψ l) -∗ (∀ (l : loc), Ψ l -∗ (∃ v, l ↦U v ∗ (l ↦U v -∗ Φ v))) -∗ awp (a_load e) R Φ. Proof. unfold a_load. iIntros "Hv HΦ". rewrite /a_ret. do 2 awp_lam. iIntros "H HΦ". awp_apply (a_wp_awp with "H"); iIntros (v) "H". awp_lam. iApply awp_bind. iApply awp_value. awp_let. iApply (awp_wand with "H"). clear v. iIntros (v). iDestruct 1 as (l ->) "HΨ". awp_lam. iDestruct ("HΦ" with "HΨ") as (v) "[Hv HΦ]". iApply awp_atomic_env. iIntros (env) "Henv HR". rewrite {2}/env_inv. ... ... @@ -130,17 +130,15 @@ Section proofs. - by iApply "HΦ". Qed. Lemma a_alloc_spec R (ev : expr) (v : val) Φ : IntoVal ev v → (∀ l, l ↦U v -∗ Φ #l) -∗ awp (a_alloc (a_ret ev)) R Φ. Lemma a_alloc_spec R Φ Ψ e : awp e R Ψ -∗ (∀ v l, Ψ v -∗ l ↦U v -∗ Φ #l) -∗ awp (a_alloc e) R Φ. Proof. intros <-%of_to_val. unfold a_alloc. iIntros "HΦ". rewrite /a_ret. do 2 awp_lam. iApply awp_bind. iApply awp_value. awp_let. iIntros "H HΦ". awp_apply (a_wp_awp with "H"); iIntros (v) "H". awp_lam. iApply awp_bind. iApply (awp_wand with "H"). clear v. iIntros (v) "HΨ". awp_lam. iApply awp_atomic_env. iIntros (env) "Henv HR". rewrite {2}/env_inv. ... ... @@ -155,11 +153,28 @@ Section proofs. by iDestruct (mapsto_valid_2 l with "Hl Hl'") as %[]. } iDestruct "Hl" as "[Hl Hl']". iMod (locking_heap_alloc σ l ULvl v with "Hl' Hσ") as "[Hσ Hl']"; eauto. iModIntro. iFrame "HR". iSplitR "HΦ Hl'". iModIntro. iFrame "HR". iSplitR "HΦ HΨ Hl'". - iExists X,(<[l:=ULvl]>σ). iFrame. iSplit. + rewrite bi.big_sepM_insert; eauto. iFrame. eauto. + iPureIntro. by rewrite locked_locs_alloc_unlocked. - by iApply "HΦ". - iApply ("HΦ" with "HΨ Hl'"). Qed. Lemma a_bin_op_spec R Φ Ψ1 Ψ2 (op : bin_op) (e1 e2: expr) : awp e1 R Ψ1 -∗ awp e2 R Ψ2 -∗ (∀ v1 v2, Ψ1 v1 -∗ Ψ2 v2 -∗ ∃ w, ⌜bin_op_eval op v1 v2 = Some w⌝ ∗ Φ w)-∗ awp (a_bin_op op e1 e2) R Φ. Proof. iIntros "H1 H2 HΦ". awp_apply (a_wp_awp with "H1"); iIntros (v1) "HΨ1". awp_lam. awp_apply (a_wp_awp with "H2"); iIntros (v2) "HΨ2". awp_lam. iApply awp_bind. iApply ((awp_par Ψ1 Ψ2) with "HΨ1 HΨ2"). iNext. iIntros (w1 w2) "HΨ1 HΨ2"; subst. iNext. awp_lam. iApply awp_ret. do 2 wp_proj. iSpecialize ("HΦ" with "HΨ1 HΨ2"). iDestruct "HΦ" as (w0) "[% H]". by wp_pure _. Qed. Lemma a_store_spec R Φ Ψ1 Ψ2 e1 e2 : ... ... @@ -212,34 +227,44 @@ Section proofs. - iApply "HΦ". iFrame. Qed. Lemma a_if_true_spec R (e1 e2 : val) Φ : awp e1 R Φ -∗ awp (a_if (a_ret #true) e1 e2) R Φ. Lemma a_if_spec R Φ Ψ (e e1 e2 : expr) `{Closed [] e1} `{Closed [] e2} : awp e R Ψ -∗ (∀ v, Ψ v -∗ (⌜v = #true⌝ ∧ awp e1 R Φ) ∨ (⌜v = #false⌝ ∧ awp e2 R Φ)) -∗ awp (a_if e (λ: <>, e1) (λ: <>, e2))%E R Φ. Proof. iIntros "HΦ". do 4 awp_lam. iApply awp_bind. iApply awp_value. awp_lam. by awp_if_true. iIntros "H HΦ". awp_apply (a_wp_awp with "H"); iIntros (v) "H". do 3 awp_lam. iApply awp_bind. iApply (awp_wand with "H"). clear v. iIntros (v) "HΨ". awp_lam. iDestruct ("HΦ" with "HΨ") as "[[% H] | [% H]]"; simplify_eq/=; by do 2 (awp_pure _). Qed. Lemma a_if_false_spec R (e1 e2 : val) Φ : awp e2 R Φ -∗ awp (a_if (a_ret #false) e1 e2) R Φ. Lemma a_if_true_spec R (e1 e2 : val) `{Closed [] e1, Closed [] e2} Φ : awp e1 R Φ -∗ awp (a_if (a_ret #true) (λ: <>, e1) (λ: <>, e2))%E R Φ. Proof. iIntros "HΦ". do 4 awp_lam. iApply awp_bind. iApply awp_value. awp_lam. by awp_if_false. iApply (a_if_spec _ _ (λ v, ⌜v = #true⌝)%I). { iApply awp_ret. iApply wp_value. eauto. } iIntros (? ->). iLeft. eauto. Qed. Lemma a_if_spec R (e e1 e2 : val) Φ: awp e R (λ cnd, (⌜cnd = #true⌝ ∧ awp e1 R Φ) ∨ (⌜cnd = #false⌝ ∧ awp e2 R Φ)) -∗ awp (a_if e e1 e2) R Φ. Lemma a_if_false_spec R (e1 e2 : val) `{Closed [] e1, Closed [] e2} Φ : awp e2 R Φ -∗ awp (a_if (a_ret #false) (λ: <>, e1) (λ: <>, e2))%E R Φ. Proof. iIntros "HΦ". do 3 awp_lam. iApply awp_bind. iApply (awp_wand with "HΦ"). iIntros (v) "[[% H] | [% H]]"; subst; by repeat awp_pure _. iIntros "HΦ". iApply (a_if_spec _ _ (λ v, ⌜v = #false⌝)%I). { iApply awp_ret. iApply wp_value. eauto. } iIntros (? ->). iRight. eauto. Qed. Lemma a_while_spec (cnd bdy : val) R Φ : ▷ awp (a_if (cnd #()) (bdy ;;;; (a_while cnd bdy))) R Φ -∗ awp (a_while cnd bdy) R Φ. Proof. iIntros "HAWP". rewrite {2}/a_while. awp_lam. awp_lam. rewrite /a_while. iApply "HAWP". Qed. End proofs.