lifting.v 5.24 KB
Newer Older
Ralf Jung's avatar
Ralf Jung committed
1
Require Import prelude.gmap iris.lifting.
2
Require Export iris.weakestpre barrier.heap_lang_tactics.
3
Import uPred.
4
Import heap_lang.
5
Local Hint Extern 0 (language.reducible _ _) => do_step ltac:(eauto 2).
6

7
Section lifting.
8 9
Context {Σ : iFunctor}.
Implicit Types P : iProp heap_lang Σ.
10 11
Implicit Types Q : val  iProp heap_lang Σ.
Implicit Types K : ectx.
Ralf Jung's avatar
Ralf Jung committed
12 13

(** Bind. *)
14
Lemma wp_bind {E e} K Q :
15
  wp E e (λ v, wp E (fill K (of_val v)) Q)  wp E (fill K e) Q.
16
Proof. apply wp_bind. Qed.
Ralf Jung's avatar
Ralf Jung committed
17

18
(** Base axioms for core primitives of the language: Stateful reductions. *)
19
Lemma wp_alloc_pst E σ e v Q :
20 21
  to_val e = Some v 
  (ownP σ   ( l, (σ !! l = None)  ownP (<[l:=v]>σ) - Q (LocV l)))
22
        wp E (Alloc e) Q.
23
Proof.
24 25
  intros; rewrite -(wp_lift_atomic_step (Alloc e) (λ v' σ' ef,
     l, ef = None  v' = LocV l  σ' = <[l:=v]>σ  σ !! l = None) σ) //;
Ralf Jung's avatar
Ralf Jung committed
26
    last by intros; inv_step; eauto 8.
27
  apply sep_mono, later_mono; first done.
28 29
  apply forall_intro=>e2; apply forall_intro=>σ2; apply forall_intro=>ef.
  apply wand_intro_l.
30
  rewrite always_and_sep_l' -associative -always_and_sep_l'.
31 32
  apply const_elim_l=>-[l [-> [-> [-> ?]]]].
  by rewrite (forall_elim l) right_id const_equiv // left_id wand_elim_r.
33
Qed.
34

35
Lemma wp_load_pst E σ l v Q :
Ralf Jung's avatar
Ralf Jung committed
36
  σ !! l = Some v 
37
  (ownP σ   (ownP σ - Q v))  wp E (Load (Loc l)) Q.
Ralf Jung's avatar
Ralf Jung committed
38
Proof.
39
  intros; rewrite -(wp_lift_atomic_det_step σ v σ None) ?right_id //;
40
    last (by intros; inv_step; eauto).
Ralf Jung's avatar
Ralf Jung committed
41
Qed.
42

43
Lemma wp_store_pst E σ l e v v' Q :
44 45
  to_val e = Some v  σ !! l = Some v' 
  (ownP σ   (ownP (<[l:=v]>σ) - Q LitUnitV))  wp E (Store (Loc l) e) Q.
Ralf Jung's avatar
Ralf Jung committed
46
Proof.
47
  intros.
48
  rewrite -(wp_lift_atomic_det_step σ LitUnitV (<[l:=v]>σ) None) ?right_id //;
49
    last by intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
50
Qed.
51

52
Lemma wp_cas_fail_pst E σ l e1 v1 e2 v2 v' Q :
53 54
  to_val e1 = Some v1  to_val e2 = Some v2  σ !! l = Some v'  v'  v1 
  (ownP σ   (ownP σ - Q LitFalseV))  wp E (Cas (Loc l) e1 e2) Q.
Ralf Jung's avatar
Ralf Jung committed
55
Proof.
56
  intros; rewrite -(wp_lift_atomic_det_step σ LitFalseV σ None) ?right_id //;
57
    last by intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
58
Qed.
59

60
Lemma wp_cas_suc_pst E σ l e1 v1 e2 v2 Q :
61 62
  to_val e1 = Some v1  to_val e2 = Some v2  σ !! l = Some v1 
  (ownP σ   (ownP (<[l:=v2]>σ) - Q LitTrueV))  wp E (Cas (Loc l) e1 e2) Q.
Ralf Jung's avatar
Ralf Jung committed
63
Proof.
64
  intros.
65
  rewrite -(wp_lift_atomic_det_step σ LitTrueV (<[l:=v2]>σ) None) ?right_id //;
66
    last by intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
67 68
Qed.

69 70
(** Base axioms for core primitives of the language: Stateless reductions *)
Lemma wp_fork E e :
71
   wp (Σ:=Σ) coPset_all e (λ _, True)  wp E (Fork e) (λ v, (v = LitUnitV)).
72
Proof.
73
  rewrite -(wp_lift_pure_det_step (Fork e) LitUnit (Some e)) //=;
74
    last by intros; inv_step; eauto.
75 76
  apply later_mono, sep_intro_True_l; last done.
  by rewrite -(wp_value' _ _ LitUnit) //; apply const_intro.
77
Qed.
78

79
Lemma wp_rec E ef e v Q :
80 81
  to_val e = Some v 
   wp E ef.[Rec ef, e /] Q  wp E (App (Rec ef) e) Q.
82
Proof.
83 84
  intros; rewrite -(wp_lift_pure_det_step (App _ _) ef.[Rec ef, e /] None)
                     ?right_id //=;
85
    last by intros; inv_step; eauto.
86
Qed.
87

88
Lemma wp_plus E n1 n2 Q :
89
   Q (LitNatV (n1 + n2))  wp E (Plus (LitNat n1) (LitNat n2)) Q.
90
Proof.
91
  rewrite -(wp_lift_pure_det_step (Plus _ _) (LitNat (n1 + n2)) None) ?right_id //;
92 93
    last by intros; inv_step; eauto.
  by rewrite -wp_value'.
Ralf Jung's avatar
Ralf Jung committed
94
Qed.
95

96
Lemma wp_le_true E n1 n2 Q :
Ralf Jung's avatar
Ralf Jung committed
97
  n1  n2 
98
   Q LitTrueV  wp E (Le (LitNat n1) (LitNat n2)) Q.
Ralf Jung's avatar
Ralf Jung committed
99
Proof.
100
  intros; rewrite -(wp_lift_pure_det_step (Le _ _) LitTrue None) ?right_id //;
Ralf Jung's avatar
Ralf Jung committed
101
    last by intros; inv_step; eauto with omega.
102
  by rewrite -wp_value'.
Ralf Jung's avatar
Ralf Jung committed
103
Qed.
104

105
Lemma wp_le_false E n1 n2 Q :
Ralf Jung's avatar
Ralf Jung committed
106
  n1 > n2 
107
   Q LitFalseV  wp E (Le (LitNat n1) (LitNat n2)) Q.
Ralf Jung's avatar
Ralf Jung committed
108
Proof.
109
  intros; rewrite -(wp_lift_pure_det_step (Le _ _) LitFalse None) ?right_id //;
Ralf Jung's avatar
Ralf Jung committed
110
    last by intros; inv_step; eauto with omega.
111
  by rewrite -wp_value'.
112
Qed.
113

114
Lemma wp_fst E e1 v1 e2 v2 Q :
115
  to_val e1 = Some v1  to_val e2 = Some v2 
116
  Q v1  wp E (Fst (Pair e1 e2)) Q.
Ralf Jung's avatar
Ralf Jung committed
117
Proof.
118
  intros; rewrite -(wp_lift_pure_det_step (Fst _) e1 None) ?right_id //;
119 120
    last by intros; inv_step; eauto.
  by rewrite -wp_value'.
Ralf Jung's avatar
Ralf Jung committed
121
Qed.
122

123
Lemma wp_snd E e1 v1 e2 v2 Q :
124 125
  to_val e1 = Some v1  to_val e2 = Some v2 
   Q v2  wp E (Snd (Pair e1 e2)) Q.
Ralf Jung's avatar
Ralf Jung committed
126
Proof.
127
  intros; rewrite -(wp_lift_pure_det_step (Snd _) e2 None) ?right_id //;
128 129
    last by intros; inv_step; eauto.
  by rewrite -wp_value'.
Ralf Jung's avatar
Ralf Jung committed
130
Qed.
131

132
Lemma wp_case_inl E e0 v0 e1 e2 Q :
133 134
  to_val e0 = Some v0 
   wp E e1.[e0/] Q  wp E (Case (InjL e0) e1 e2) Q.
Ralf Jung's avatar
Ralf Jung committed
135
Proof.
136
  intros; rewrite -(wp_lift_pure_det_step (Case _ _ _) e1.[e0/] None) ?right_id //;
137
    last by intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
138
Qed.
139

140
Lemma wp_case_inr E e0 v0 e1 e2 Q :
141 142
  to_val e0 = Some v0 
   wp E e2.[e0/] Q  wp E (Case (InjR e0) e1 e2) Q.
Ralf Jung's avatar
Ralf Jung committed
143
Proof.
144
  intros; rewrite -(wp_lift_pure_det_step (Case _ _ _) e2.[e0/] None) ?right_id //;
145
    last by intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
146
Qed.
147

Ralf Jung's avatar
Ralf Jung committed
148
(** Some derived stateless axioms *)
149
Lemma wp_le E n1 n2 P Q :
150 151
  (n1  n2  P   Q LitTrueV) 
  (n1 > n2  P   Q LitFalseV) 
152
  P  wp E (Le (LitNat n1) (LitNat n2)) Q.
Ralf Jung's avatar
Ralf Jung committed
153
Proof.
154 155
  intros; destruct (decide (n1  n2)).
  * rewrite -wp_le_true; auto.
Ralf Jung's avatar
Ralf Jung committed
156
  * rewrite -wp_le_false; auto with omega.
Ralf Jung's avatar
Ralf Jung committed
157
Qed.
158

159
End lifting.