lifting.v 5.99 KB
Newer Older
1
From iris.program_logic Require Export ectx_weakestpre.
2
From iris.program_logic Require Import ownership. (* for ownP *)
3
From iris.heap_lang Require Export lang.
4
From iris.heap_lang Require Import tactics.
5
Import uPred.
6
Local Hint Extern 0 (head_reducible _ _) => do_step eauto 2.
7

8
Section lifting.
9
Context {Σ : iFunctor}.
10
11
Implicit Types P Q : iProp heap_lang Σ.
Implicit Types Φ : val  iProp heap_lang Σ.
12
Implicit Types K : ectx.
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

20
(** Base axioms for core primitives of the language: Stateful reductions. *)
21
Lemma wp_alloc_pst E σ e v Φ :
22
  to_val e = Some v 
23
  ( ownP σ   ( l, σ !! l = None  ownP (<[l:=v]>σ) - Φ (LocV l)))
24
   WP Alloc e @ E {{ Φ }}.
25
Proof.
Ralf Jung's avatar
Ralf Jung committed
26
  (* TODO: This works around ssreflect bug #22. *)
27
28
  intros. set (φ (e' : expr []) σ' ef :=  l,
    ef = None  e' = Loc l  σ' = <[l:=v]>σ  σ !! l = None).
29
  rewrite -(wp_lift_atomic_head_step (Alloc e) φ σ) // /φ;
30
    last (by intros; inv_step; eauto 8); last (by simpl; eauto).
31
  apply sep_mono, later_mono; first done.
32
  apply forall_intro=>v2; apply forall_intro=>σ2; apply forall_intro=>ef.
33
  apply wand_intro_l.
34
  rewrite always_and_sep_l -assoc -always_and_sep_l.
35
36
37
38
  apply const_elim_l=>-[l [-> [Hl [-> ?]]]].
  rewrite (forall_elim l) right_id const_equiv // left_id wand_elim_r.
  rewrite -(of_to_val (Loc l) (LocV l)) // in Hl. apply of_val_inj in Hl.
  by subst.
39
Qed.
40

41
Lemma wp_load_pst E σ l v Φ :
Ralf Jung's avatar
Ralf Jung committed
42
  σ !! l = Some v 
43
  ( ownP σ   (ownP σ - Φ v))  WP Load (Loc l) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
44
Proof.
45
  intros. rewrite -(wp_lift_atomic_det_head_step σ v σ None) ?right_id //;
46
    last (by intros; inv_step; eauto using to_of_val); simpl; by eauto.
Ralf Jung's avatar
Ralf Jung committed
47
Qed.
48

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

58
Lemma wp_cas_fail_pst E σ l e1 v1 e2 v2 v' Φ :
59
  to_val e1 = Some v1  to_val e2 = Some v2  σ !! l = Some v'  v'  v1 
60
  ( ownP σ   (ownP σ - Φ (LitV $ LitBool false)))
61
   WP CAS (Loc l) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
62
Proof.
63
  intros. rewrite -(wp_lift_atomic_det_head_step σ (LitV $ LitBool false) σ None)
64
65
    ?right_id //; last (by intros; inv_step; eauto);
    simpl; split_and?; by eauto.
Ralf Jung's avatar
Ralf Jung committed
66
Qed.
67

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

78
(** Base axioms for core primitives of the language: Stateless reductions *)
79
Lemma wp_fork E e Φ :
80
  ( Φ (LitV LitUnit)   WP e {{ λ _, True }})  WP Fork e @ E {{ Φ }}.
81
Proof.
82
  rewrite -(wp_lift_pure_det_head_step (Fork e) (Lit LitUnit) (Some e)) //=;
83
    last by intros; inv_step; eauto.
84
  rewrite later_sep -(wp_value _ _ (Lit _)) //.
85
Qed.
86

87
Lemma wp_rec E f x e1 e2 v Φ :
88
  to_val e2 = Some v 
89
90
   WP subst' x e2 (subst' f (Rec f x e1) e1) @ E {{ Φ }}
   WP App (Rec f x e1) e2 @ E {{ Φ }}.
91
Proof.
92
  intros. rewrite -(wp_lift_pure_det_head_step (App _ _)
93
    (subst' x e2 (subst' f (Rec f x e1) e1)) None) //= ?right_id;
94
    intros; inv_step; eauto.
95
Qed.
96

97
98
Lemma wp_rec' E f x erec e1 e2 v2 Φ :
  e1 = Rec f x erec 
99
  to_val e2 = Some v2 
100
101
   WP subst' x e2 (subst' f e1 erec) @ E {{ Φ }}
   WP App e1 e2 @ E {{ Φ }}.
102
103
Proof. intros ->. apply wp_rec. Qed.

104
Lemma wp_un_op E op l l' Φ :
105
  un_op_eval op l = Some l' 
106
   Φ (LitV l')  WP UnOp op (Lit l) @ E {{ Φ }}.
107
Proof.
108
  intros. rewrite -(wp_lift_pure_det_head_step (UnOp op _) (Lit l') None)
109
    ?right_id -?wp_value //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
110
Qed.
111

112
Lemma wp_bin_op E op l1 l2 l' Φ :
113
  bin_op_eval op l1 l2 = Some l' 
114
   Φ (LitV l')  WP BinOp op (Lit l1) (Lit l2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
115
Proof.
116
  intros Heval. rewrite -(wp_lift_pure_det_head_step (BinOp op _ _) (Lit l') None)
117
    ?right_id -?wp_value //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
118
Qed.
119

120
Lemma wp_if_true E e1 e2 Φ :
121
   WP e1 @ E {{ Φ }}  WP If (Lit (LitBool true)) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
122
Proof.
123
  rewrite -(wp_lift_pure_det_head_step (If _ _ _) e1 None)
124
    ?right_id //; intros; inv_step; eauto.
125
126
Qed.

127
Lemma wp_if_false E e1 e2 Φ :
128
   WP e2 @ E {{ Φ }}  WP If (Lit (LitBool false)) e1 e2 @ E {{ Φ }}.
129
Proof.
130
  rewrite -(wp_lift_pure_det_head_step (If _ _ _) e2 None)
131
    ?right_id //; intros; inv_step; eauto.
132
Qed.
133

134
Lemma wp_fst E e1 v1 e2 v2 Φ :
135
  to_val e1 = Some v1  to_val e2 = Some v2 
136
   Φ v1  WP Fst (Pair e1 e2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
137
Proof.
138
  intros. rewrite -(wp_lift_pure_det_head_step (Fst _) e1 None)
139
    ?right_id -?wp_value //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
140
Qed.
141

142
Lemma wp_snd E e1 v1 e2 v2 Φ :
143
  to_val e1 = Some v1  to_val e2 = Some v2 
144
   Φ v2  WP Snd (Pair e1 e2) @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
145
Proof.
146
  intros. rewrite -(wp_lift_pure_det_head_step (Snd _) e2 None)
147
    ?right_id -?wp_value //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
148
Qed.
149

150
Lemma wp_case_inl E e0 v0 e1 e2 Φ :
151
  to_val e0 = Some v0 
152
   WP App e1 e0 @ E {{ Φ }}  WP Case (InjL e0) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
153
Proof.
154
  intros. rewrite -(wp_lift_pure_det_head_step (Case _ _ _)
155
    (App e1 e0) None) ?right_id //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
156
Qed.
157

158
Lemma wp_case_inr E e0 v0 e1 e2 Φ :
159
  to_val e0 = Some v0 
160
   WP App e2 e0 @ E {{ Φ }}  WP Case (InjR e0) e1 e2 @ E {{ Φ }}.
Ralf Jung's avatar
Ralf Jung committed
161
Proof.
162
  intros. rewrite -(wp_lift_pure_det_head_step (Case _ _ _)
163
    (App e2 e0) None) ?right_id //; intros; inv_step; eauto.
Ralf Jung's avatar
Ralf Jung committed
164
Qed.
165

166
End lifting.