hoare.v 4.61 KB
Newer Older
1 2
From iris.program_logic Require Export weakestpre.
From iris.base_logic.lib Require Export viewshifts.
3
From iris.proofmode Require Import tactics.
4
Set Default Proof Using "Type".
Robbert Krebbers's avatar
Robbert Krebbers committed
5

6 7
Definition ht `{irisG Λ Σ} (E : coPset) (P : iProp Σ)
    (e : expr Λ) (Φ : val Λ  iProp Σ) : iProp Σ :=
8
  ( (P - WP e @ E {{ Φ }}))%I.
9
Instance: Params (@ht) 4.
Robbert Krebbers's avatar
Robbert Krebbers committed
10

11
Notation "{{ P } } e @ E {{ Φ } }" := (ht E P%I e%E Φ%I)
12 13
  (at level 20, P, e, Φ at level 200,
   format "{{  P  } }  e  @  E  {{  Φ  } }") : C_scope.
14
Notation "{{ P } } e {{ Φ } }" := (ht  P%I e%E Φ%I)
15 16
  (at level 20, P, e, Φ at level 200,
   format "{{  P  } }  e  {{  Φ  } }") : C_scope.
Robbert Krebbers's avatar
Robbert Krebbers committed
17

18
Notation "{{ P } } e @ E {{ v , Q } }" := (ht E P%I e%E (λ v, Q)%I)
19 20
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  @  E  {{  v ,  Q  } }") : C_scope.
21
Notation "{{ P } } e {{ v , Q } }" := (ht  P%I e%E (λ v, Q)%I)
22 23 24
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  {{  v ,  Q  } }") : C_scope.

Robbert Krebbers's avatar
Robbert Krebbers committed
25
Section hoare.
26 27 28
Context `{irisG Λ Σ}.
Implicit Types P Q : iProp Σ.
Implicit Types Φ Ψ : val Λ  iProp Σ.
29
Implicit Types v : val Λ.
Robbert Krebbers's avatar
Robbert Krebbers committed
30 31 32
Import uPred.

Global Instance ht_ne E n :
33
  Proper (dist n ==> eq ==> pointwise_relation _ (dist n) ==> dist n) (ht E).
Ralf Jung's avatar
Ralf Jung committed
34
Proof. solve_proper. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
35
Global Instance ht_proper E :
36
  Proper (() ==> eq ==> pointwise_relation _ () ==> ()) (ht E).
Robbert Krebbers's avatar
Robbert Krebbers committed
37
Proof. solve_proper. Qed.
38
Lemma ht_mono E P P' Φ Φ' e :
39
  (P  P')  ( v, Φ' v  Φ v)  {{ P' }} e @ E {{ Φ' }}  {{ P }} e @ E {{ Φ }}.
40
Proof. by intros; apply persistently_mono, wand_mono, wp_mono. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
41
Global Instance ht_mono' E :
42
  Proper (flip () ==> eq ==> pointwise_relation _ () ==> ()) (ht E).
Robbert Krebbers's avatar
Robbert Krebbers committed
43
Proof. solve_proper. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
44

45
Lemma ht_alt E P Φ e : (P  WP e @ E {{ Φ }})  {{ P }} e @ E {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
46
Proof. iIntros (Hwp) "!# HP". by iApply Hwp. Qed.
47

Ralf Jung's avatar
Ralf Jung committed
48
Lemma ht_val E v : {{ True }} of_val v @ E {{ v', v = v' }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
49
Proof. iIntros "!# _". by iApply wp_value'. Qed.
50

51
Lemma ht_vs E P P' Φ Φ' e :
52
  (P ={E}=> P')  {{ P' }} e @ E {{ Φ' }}  ( v, Φ' v ={E}=> Φ v)
53
   {{ P }} e @ E {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
54
Proof.
55
  iIntros "(#Hvs & #Hwp & #HΦ) !# HP". iMod ("Hvs" with "HP") as "HP".
Robbert Krebbers's avatar
Robbert Krebbers committed
56
  iApply wp_fupd. iApply (wp_wand with "[HP]"); [by iApply "Hwp"|].
57
  iIntros (v) "Hv". by iApply "HΦ".
Robbert Krebbers's avatar
Robbert Krebbers committed
58
Qed.
59

60
Lemma ht_atomic E1 E2 P P' Φ Φ' e :
Robbert Krebbers's avatar
Robbert Krebbers committed
61
  Atomic e 
62
  (P ={E1,E2}=> P')  {{ P' }} e @ E2 {{ Φ' }}  ( v, Φ' v ={E2,E1}=> Φ v)
63
   {{ P }} e @ E1 {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
64
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
65
  iIntros (?) "(#Hvs & #Hwp & #HΦ) !# HP". iApply (wp_atomic _ E2); auto.
66
  iMod ("Hvs" with "HP") as "HP". iModIntro.
Robbert Krebbers's avatar
Robbert Krebbers committed
67
  iApply (wp_wand with "[HP]"); [by iApply "Hwp"|].
68
  iIntros (v) "Hv". by iApply "HΦ".
Robbert Krebbers's avatar
Robbert Krebbers committed
69
Qed.
70

71
Lemma ht_bind `{LanguageCtx Λ K} E P Φ Φ' e :
72
  {{ P }} e @ E {{ Φ }}  ( v, {{ Φ v }} K (of_val v) @ E {{ Φ' }})
73
   {{ P }} K e @ E {{ Φ' }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
74
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
75
  iIntros "[#Hwpe #HwpK] !# HP". iApply wp_bind.
Robbert Krebbers's avatar
Robbert Krebbers committed
76
  iApply (wp_wand with "[HP]"); [by iApply "Hwpe"|].
77
  iIntros (v) "Hv". by iApply "HwpK".
Robbert Krebbers's avatar
Robbert Krebbers committed
78
Qed.
79

80
Lemma ht_mask_weaken E1 E2 P Φ e :
81
  E1  E2  {{ P }} e @ E1 {{ Φ }}  {{ P }} e @ E2 {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
82
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
83
  iIntros (?) "#Hwp !# HP". iApply (wp_mask_mono E1 E2); try done.
Robbert Krebbers's avatar
Robbert Krebbers committed
84 85
  by iApply "Hwp".
Qed.
86

87
Lemma ht_frame_l E P Φ R e :
88
  {{ P }} e @ E {{ Φ }}  {{ R  P }} e @ E {{ v, R  Φ v }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
89
Proof. iIntros "#Hwp !# [$ HP]". by iApply "Hwp". Qed.
90

91
Lemma ht_frame_r E P Φ R e :
92
  {{ P }} e @ E {{ Φ }}  {{ P  R }} e @ E {{ v, Φ v  R }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
93
Proof. iIntros "#Hwp !# [HP $]". by iApply "Hwp". Qed.
94

95 96
Lemma ht_frame_step_l E1 E2 P R1 R2 e Φ :
  to_val e = None  E2  E1 
97
  (R1 ={E1,E2}=>  |={E2,E1}=> R2)  {{ P }} e @ E2 {{ Φ }}
98
   {{ R1  P }} e @ E1 {{ λ v, R2  Φ v }}.
99
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
100
  iIntros (??) "[#Hvs #Hwp] !# [HR HP]".
101 102
  iApply (wp_frame_step_l E1 E2); try done.
  iSplitL "HR"; [by iApply "Hvs"|by iApply "Hwp"].
103 104
Qed.

105 106
Lemma ht_frame_step_r E1 E2 P R1 R2 e Φ :
  to_val e = None  E2  E1 
107
  (R1 ={E1,E2}=>  |={E2,E1}=> R2)  {{ P }} e @ E2 {{ Φ }}
108
   {{ P  R1 }} e @ E1 {{ λ v, Φ v  R2 }}.
109
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
110
  iIntros (??) "[#Hvs #Hwp] !# [HP HR]".
111 112
  iApply (wp_frame_step_r E1 E2); try done.
  iSplitR "HR"; [by iApply "Hwp"|by iApply "Hvs"].
113 114
Qed.

Ralf Jung's avatar
Ralf Jung committed
115
Lemma ht_frame_step_l' E P R e Φ :
Robbert Krebbers's avatar
Robbert Krebbers committed
116
  to_val e = None 
117
  {{ P }} e @ E {{ Φ }}  {{  R  P }} e @ E {{ v, R  Φ v }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
118
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
119
  iIntros (?) "#Hwp !# [HR HP]".
Ralf Jung's avatar
Ralf Jung committed
120
  iApply wp_frame_step_l'; try done. iFrame "HR". by iApply "Hwp".
Robbert Krebbers's avatar
Robbert Krebbers committed
121
Qed.
122

Ralf Jung's avatar
Ralf Jung committed
123
Lemma ht_frame_step_r' E P Φ R e :
Robbert Krebbers's avatar
Robbert Krebbers committed
124
  to_val e = None 
125
  {{ P }} e @ E {{ Φ }}  {{ P   R }} e @ E {{ v, Φ v  R }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
126
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
127
  iIntros (?) "#Hwp !# [HP HR]".
Ralf Jung's avatar
Ralf Jung committed
128
  iApply wp_frame_step_r'; try done. iFrame "HR". by iApply "Hwp".
Robbert Krebbers's avatar
Robbert Krebbers committed
129
Qed.
130
End hoare.