lifting.v 5.84 KB
Newer Older
1 2
From iris.program_logic Require Export weakestpre.
From iris.program_logic Require Import ownership ectx_lifting. (* for ownP *)
3
From iris.heap_lang Require Export lang.
4
From iris.heap_lang Require Import tactics.
5
From iris.proofmode Require Import weakestpre.
6
Import uPred.
Robbert Krebbers's avatar
Robbert Krebbers committed
7
Local Hint Extern 0 (head_reducible _ _) => do_head_step eauto 2.
8

9
Section lifting.
10
Context {Σ : iFunctor}.
11 12
Implicit Types P Q : iProp heap_lang Σ.
Implicit Types Φ : val  iProp heap_lang Σ.
13
Implicit Types ef : option expr.
Ralf Jung's avatar
Ralf Jung committed
14

15
(** Bind. This bundles some arguments that wp_ectx_bind leaves as indices. *)
16
Lemma wp_bind {E e} K Φ :
17
  WP e @ E {{ v, WP fill K (of_val v) @ E {{ Φ }} }}  WP fill K e @ E {{ Φ }}.
18
Proof. exact: wp_ectx_bind. Qed.
Ralf Jung's avatar
Ralf Jung committed
19

Ralf Jung's avatar
Ralf Jung committed
20 21 22 23 24
Lemma wp_bindi {E e} Ki Φ :
  WP e @ E {{ v, WP fill_item Ki (of_val v) @ E {{ Φ }} }} 
     WP fill_item Ki e @ E {{ Φ }}.
Proof. exact: weakestpre.wp_bind. Qed.

25
(** Base axioms for core primitives of the language: Stateful reductions. *)
26
Lemma wp_alloc_pst E σ e v Φ :
27
  to_val e = Some v 
28
   ownP σ   ( l, σ !! l = None  ownP (<[l:=v]>σ) ={E}= Φ (LitV (LitLoc l)))
29
   WP Alloc e @ E {{ Φ }}.
30
Proof.
31
  iIntros (?)  "[HP HΦ]".
32
  iApply (wp_lift_atomic_head_step (Alloc e) σ); try (by simpl; eauto).
33
  iFrame "HP". iNext. iIntros (v2 σ2 ef) "[% HP]". inv_head_step.
34 35
  match goal with H: _ = of_val v2 |- _ => apply (inj of_val (LitV _)) in H end.
  subst v2. iSplit; last done. iApply "HΦ"; by iSplit.
36
Qed.
37

38
Lemma wp_load_pst E σ l v Φ :
Ralf Jung's avatar
Ralf Jung committed
39
  σ !! l = Some v 
40
   ownP σ   (ownP σ ={E}= Φ v)  WP Load (Lit (LitLoc l)) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
41
Proof.
42
  intros. rewrite -(wp_lift_atomic_det_head_step σ v σ None) ?right_id //;
Robbert Krebbers's avatar
Robbert Krebbers committed
43
    last (by intros; inv_head_step; eauto using to_of_val); simpl; by eauto.
Ralf Jung's avatar
Ralf Jung committed
44
Qed.
45

46
Lemma wp_store_pst E σ l e v v' Φ :
47
  to_val e = Some v  σ !! l = Some v' 
48
   ownP σ   (ownP (<[l:=v]>σ) ={E}= Φ (LitV LitUnit))
49
   WP Store (Lit (LitLoc l)) e @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
50
Proof.
51
  intros. rewrite-(wp_lift_atomic_det_head_step σ (LitV LitUnit) (<[l:=v]>σ) None)
Robbert Krebbers's avatar
Robbert Krebbers committed
52
    ?right_id //; last (by intros; inv_head_step; eauto); simpl; by eauto.
Ralf Jung's avatar
Ralf Jung committed
53
Qed.
54

55
Lemma wp_cas_fail_pst E σ l e1 v1 e2 v2 v' Φ :
56
  to_val e1 = Some v1  to_val e2 = Some v2  σ !! l = Some v'  v'  v1 
57
   ownP σ   (ownP σ ={E}= Φ (LitV $ LitBool false))
58
   WP CAS (Lit (LitLoc l)) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
59
Proof.
60
  intros. rewrite -(wp_lift_atomic_det_head_step σ (LitV $ LitBool false) σ None)
Robbert Krebbers's avatar
Robbert Krebbers committed
61
    ?right_id //; last (by intros; inv_head_step; eauto);
62
    simpl; by eauto 10.
Ralf Jung's avatar
Ralf Jung committed
63
Qed.
64

65
Lemma wp_cas_suc_pst E σ l e1 v1 e2 v2 Φ :
66
  to_val e1 = Some v1  to_val e2 = Some v2  σ !! l = Some v1 
67
   ownP σ   (ownP (<[l:=v2]>σ) ={E}= Φ (LitV $ LitBool true))
68
   WP CAS (Lit (LitLoc l)) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
69
Proof.
70
  intros. rewrite -(wp_lift_atomic_det_head_step σ (LitV $ LitBool true)
Robbert Krebbers's avatar
Robbert Krebbers committed
71
    (<[l:=v2]>σ) None) ?right_id //; last (by intros; inv_head_step; eauto);
72
    simpl; by eauto 10.
Ralf Jung's avatar
Ralf Jung committed
73 74
Qed.

75
(** Base axioms for core primitives of the language: Stateless reductions *)
76
Lemma wp_fork E e Φ :
77
   (|={E}=> Φ (LitV LitUnit))   WP e {{ _, True }}  WP Fork e @ E {{ Φ }}.
78
Proof.
79
  rewrite -(wp_lift_pure_det_head_step (Fork e) (Lit LitUnit) (Some e)) //=;
Robbert Krebbers's avatar
Robbert Krebbers committed
80
    last by intros; inv_head_step; eauto.
81
  rewrite later_sep -(wp_value_pvs _ _ (Lit _)) //.
82
Qed.
83

84
Lemma wp_rec E f x erec e1 e2 Φ :
85
  e1 = Rec f x erec 
86
  is_Some (to_val e2) 
87
  Closed (f :b: x :b: []) erec 
Robbert Krebbers's avatar
Robbert Krebbers committed
88
   WP subst' x e2 (subst' f e1 erec) @ E {{ Φ }}  WP App e1 e2 @ E {{ Φ }}.
89
Proof.
90
  intros -> [v2 ?] ?. rewrite -(wp_lift_pure_det_head_step (App _ _)
91 92 93
    (subst' x e2 (subst' f (Rec f x erec) erec)) None) //= ?right_id;
    intros; inv_head_step; eauto.
Qed.
94

95
Lemma wp_un_op E op l l' Φ :
96
  un_op_eval op l = Some l' 
97
   (|={E}=> Φ (LitV l'))  WP UnOp op (Lit l) @ E {{ Φ }}.
98
Proof.
99
  intros. rewrite -(wp_lift_pure_det_head_step (UnOp op _) (Lit l') None)
100
    ?right_id -?wp_value_pvs //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
101
Qed.
102

103
Lemma wp_bin_op E op l1 l2 l' Φ :
104
  bin_op_eval op l1 l2 = Some l' 
105
   (|={E}=> Φ (LitV l'))  WP BinOp op (Lit l1) (Lit l2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
106
Proof.
107
  intros Heval. rewrite -(wp_lift_pure_det_head_step (BinOp op _ _) (Lit l') None)
108
    ?right_id -?wp_value_pvs //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
109
Qed.
110

111
Lemma wp_if_true E e1 e2 Φ :
112
   WP e1 @ E {{ Φ }}  WP If (Lit (LitBool true)) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
113
Proof.
114
  rewrite -(wp_lift_pure_det_head_step (If _ _ _) e1 None)
Robbert Krebbers's avatar
Robbert Krebbers committed
115
    ?right_id //; intros; inv_head_step; eauto.
116 117
Qed.

118
Lemma wp_if_false E e1 e2 Φ :
119
   WP e2 @ E {{ Φ }}  WP If (Lit (LitBool false)) e1 e2 @ E {{ Φ }}.
120
Proof.
121
  rewrite -(wp_lift_pure_det_head_step (If _ _ _) e2 None)
Robbert Krebbers's avatar
Robbert Krebbers committed
122
    ?right_id //; intros; inv_head_step; eauto.
123
Qed.
124

125 126
Lemma wp_fst E e1 v1 e2 Φ :
  to_val e1 = Some v1  is_Some (to_val e2) 
127
   (|={E}=> Φ v1)  WP Fst (Pair e1 e2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
128
Proof.
129
  intros ? [v2 ?]. rewrite -(wp_lift_pure_det_head_step (Fst _) e1 None)
130
    ?right_id -?wp_value_pvs //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
131
Qed.
132

133 134
Lemma wp_snd E e1 e2 v2 Φ :
  is_Some (to_val e1)  to_val e2 = Some v2 
135
   (|={E}=> Φ v2)  WP Snd (Pair e1 e2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
136
Proof.
137
  intros [v1 ?] ?. rewrite -(wp_lift_pure_det_head_step (Snd _) e2 None)
138
    ?right_id -?wp_value_pvs //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
139
Qed.
140

141 142
Lemma wp_case_inl E e0 e1 e2 Φ :
  is_Some (to_val e0) 
143
   WP App e1 e0 @ E {{ Φ }}  WP Case (InjL e0) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
144
Proof.
145
  intros [v0 ?]. rewrite -(wp_lift_pure_det_head_step (Case _ _ _)
Robbert Krebbers's avatar
Robbert Krebbers committed
146
    (App e1 e0) None) ?right_id //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
147
Qed.
148

149 150
Lemma wp_case_inr E e0 e1 e2 Φ :
  is_Some (to_val e0) 
151
   WP App e2 e0 @ E {{ Φ }}  WP Case (InjR e0) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
152
Proof.
153
  intros [v0 ?]. rewrite -(wp_lift_pure_det_head_step (Case _ _ _)
Robbert Krebbers's avatar
Robbert Krebbers committed
154
    (App e2 e0) None) ?right_id //; intros; inv_head_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
155
Qed.
156
End lifting.