lifting.v 3.23 KB
Newer Older
1
From iris.program_logic Require Export weakestpre.
2
From iris.program_logic Require Import ownership.
3
From iris.proofmode Require Import pviewshifts.
Robbert Krebbers's avatar
Robbert Krebbers committed
4
5

Section lifting.
6
Context `{irisG Λ Σ}.
7
8
9
Implicit Types v : val Λ.
Implicit Types e : expr Λ.
Implicit Types σ : state Λ.
10
11
Implicit Types P Q : iProp Σ.
Implicit Types Φ : val Λ  iProp Σ.
Robbert Krebbers's avatar
Robbert Krebbers committed
12

13
14
15
Lemma wp_lift_step E Φ e1 :
  to_val e1 = None 
  (|={E,}=>  σ1,  reducible e1 σ1   ownP σ1 
16
17
      e2 σ2 efs,  prim_step e1 σ1 e2 σ2 efs  ownP σ2
          ={,E}= WP e2 @ E {{ Φ }}  wp_fork efs)
18
   WP e1 @ E {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
19
Proof.
20
  iIntros (?) "H". rewrite wp_unfold /wp_pre; iRight; iSplit; auto.
Robbert Krebbers's avatar
Robbert Krebbers committed
21
  iIntros (σ1) "Hσ". iVs "H" as (σ1') "(% & >Hσf & H)".
22
  iDestruct (ownP_agree σ1 σ1' with "[#]") as %<-; first by iFrame.
23
  iVsIntro; iSplit; [done|]; iNext; iIntros (e2 σ2 efs Hstep).
24
25
  iVs (ownP_update σ1 σ2 with "[-H]") as "[$ ?]"; first by iFrame.
  iApply "H"; eauto.
Robbert Krebbers's avatar
Robbert Krebbers committed
26
Qed.
27

28
Lemma wp_lift_pure_step E Φ e1 :
Robbert Krebbers's avatar
Robbert Krebbers committed
29
  to_val e1 = None 
30
  ( σ1, reducible e1 σ1) 
31
32
  ( σ1 e2 σ2 efs, prim_step e1 σ1 e2 σ2 efs  σ1 = σ2) 
  (  e2 efs σ,  prim_step e1 σ e2 σ efs  WP e2 @ E {{ Φ }}  wp_fork efs)
33
   WP e1 @ E {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
34
Proof.
35
36
  iIntros (He Hsafe Hstep) "H". rewrite wp_unfold /wp_pre; iRight; iSplit; auto.
  iIntros (σ1) "Hσ". iApply pvs_intro'; [set_solver|iIntros "Hclose"].
37
38
  iSplit; [done|]; iNext; iIntros (e2 σ2 efs ?).
  destruct (Hstep σ1 e2 σ2 efs); auto; subst.
39
  iVs "Hclose"; iVsIntro. iFrame "Hσ". iApply "H"; auto.
Robbert Krebbers's avatar
Robbert Krebbers committed
40
Qed.
41
42

(** Derived lifting lemmas. *)
43
Lemma wp_lift_atomic_step {E Φ} e1 σ1 :
44
  atomic e1 
45
  reducible e1 σ1 
46
47
   ownP σ1   ( v2 σ2 efs,
     prim_step e1 σ1 (of_val v2) σ2 efs  ownP σ2 - (|={E}=> Φ v2)  wp_fork efs)
48
   WP e1 @ E {{ Φ }}.
49
Proof.
50
51
52
53
  iIntros (Hatomic ?) "[Hσ H]".
  iApply (wp_lift_step E _ e1); eauto using reducible_not_val.
  iApply pvs_intro'; [set_solver|iIntros "Hclose"].
  iExists σ1. iFrame "Hσ"; iSplit; eauto.
54
55
56
  iNext; iIntros (e2 σ2 efs) "[% Hσ]".
  edestruct (Hatomic σ1 e2 σ2 efs) as [v2 <-%of_to_val]; eauto.
  iDestruct ("H" $! v2 σ2 efs with "[Hσ]") as "[HΦ $]"; first by eauto.
57
  iVs "Hclose". iVs "HΦ". iApply wp_value; auto using to_of_val.
58
59
Qed.

60
Lemma wp_lift_atomic_det_step {E Φ e1} σ1 v2 σ2 efs :
61
  atomic e1 
62
  reducible e1 σ1 
63
64
65
  ( e2' σ2' efs', prim_step e1 σ1 e2' σ2' efs' 
                   σ2 = σ2'  to_val e2' = Some v2  efs = efs') 
   ownP σ1   (ownP σ2 - (|={E}=> Φ v2)  wp_fork efs)  WP e1 @ E {{ Φ }}.
66
Proof.
67
  iIntros (?? Hdet) "[Hσ1 Hσ2]". iApply (wp_lift_atomic_step _ σ1); try done.
68
  iFrame. iNext. iIntros (v2' σ2' efs') "[% Hσ2']".
69
  edestruct Hdet as (->&->%of_to_val%(inj of_val)&->). done. by iApply "Hσ2".
70
71
Qed.

72
Lemma wp_lift_pure_det_step {E Φ} e1 e2 efs :
73
74
  to_val e1 = None 
  ( σ1, reducible e1 σ1) 
75
76
  ( σ1 e2' σ2 efs', prim_step e1 σ1 e2' σ2 efs'  σ1 = σ2  e2 = e2'  efs = efs')
   (WP e2 @ E {{ Φ }}  wp_fork efs)  WP e1 @ E {{ Φ }}.
77
Proof.
78
  iIntros (?? Hpuredet) "?". iApply (wp_lift_pure_step E); try done.
79
  by intros; eapply Hpuredet. iNext. by iIntros (e' efs' σ (_&->&->)%Hpuredet).
80
Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
81
End lifting.