hoare.v 5.15 KB
Newer Older
1
From iris.program_logic Require Export weakestpre viewshifts.
2
From iris.proofmode Require Import tactics.
Robbert Krebbers's avatar
Robbert Krebbers committed
3

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

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

22
Notation "{{ P } } e @ E {{ v , Q } }" := (ht E P e%E (λ v, Q))
23 24
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  @  E  {{  v ,  Q  } }") : uPred_scope.
25
Notation "{{ P } } e {{ v , Q } }" := (ht  P e%E (λ v, Q))
26 27
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  {{  v ,  Q  } }") : uPred_scope.
28
Notation "{{ P } } e @ E {{ v , Q } }" := (True  ht E P e%E (λ v, Q))
29 30
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  @  E  {{  v ,  Q  } }") : C_scope.
31
Notation "{{ P } } e {{ v , Q } }" := (True  ht  P e%E (λ v, Q))
32 33 34
  (at level 20, P, e, Q at level 200,
   format "{{  P  } }  e  {{  v ,  Q  } }") : C_scope.

Robbert Krebbers's avatar
Robbert Krebbers committed
35
Section hoare.
36 37 38
Context `{irisG Λ Σ}.
Implicit Types P Q : iProp Σ.
Implicit Types Φ Ψ : val Λ  iProp Σ.
39
Implicit Types v : val Λ.
Robbert Krebbers's avatar
Robbert Krebbers committed
40 41 42
Import uPred.

Global Instance ht_ne E n :
43
  Proper (dist n ==> eq==>pointwise_relation _ (dist n) ==> dist n) (ht E).
Ralf Jung's avatar
Ralf Jung committed
44
Proof. solve_proper. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
45
Global Instance ht_proper E :
46
  Proper (() ==> eq ==> pointwise_relation _ () ==> ()) (ht E).
Robbert Krebbers's avatar
Robbert Krebbers committed
47
Proof. solve_proper. Qed.
48
Lemma ht_mono E P P' Φ Φ' e :
49
  (P  P')  ( v, Φ' v  Φ v)  {{ P' }} e @ E {{ Φ' }}  {{ P }} e @ E {{ Φ }}.
50
Proof. by intros; apply always_mono, wand_mono, wp_mono. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
51
Global Instance ht_mono' E :
52
  Proper (flip () ==> eq ==> pointwise_relation _ () ==> ()) (ht E).
Robbert Krebbers's avatar
Robbert Krebbers committed
53
Proof. solve_proper. Qed.
Robbert Krebbers's avatar
Robbert Krebbers committed
54

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

58
Lemma ht_val E v : {{ True }} of_val v @ E {{ v', v = v' }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
59
Proof. iIntros "!# _". by iApply wp_value'. Qed.
60

61
Lemma ht_vs E P P' Φ Φ' e :
62
  (P ={E}=> P')  {{ P' }} e @ E {{ Φ' }}  ( v, Φ' v ={E}=> Φ v)
63
   {{ P }} e @ E {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
64
Proof.
65
  iIntros "(#Hvs & #Hwp & #HΦ) !# HP". iMod ("Hvs" with "HP") as "HP".
66
  iApply wp_fupd; iApply wp_wand_r; iSplitL; [by iApply "Hwp"|].
67
  iIntros (v) "Hv". by iApply "HΦ".
Robbert Krebbers's avatar
Robbert Krebbers committed
68
Qed.
69

70
Lemma ht_atomic E1 E2 P P' Φ Φ' e :
71
  atomic e 
72
  (P ={E1,E2}=> P')  {{ P' }} e @ E2 {{ Φ' }}  ( v, Φ' v ={E2,E1}=> Φ v)
73
   {{ P }} e @ E1 {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
74
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
75
  iIntros (?) "(#Hvs & #Hwp & #HΦ) !# HP". iApply (wp_atomic _ E2); auto.
76
  iMod ("Hvs" with "HP") as "HP". iModIntro.
Robbert Krebbers's avatar
Robbert Krebbers committed
77
  iApply wp_wand_r; iSplitL; [by iApply "Hwp"|].
78
  iIntros (v) "Hv". by iApply "HΦ".
Robbert Krebbers's avatar
Robbert Krebbers committed
79
Qed.
80

81
Lemma ht_bind `{LanguageCtx Λ K} E P Φ Φ' e :
82
  {{ P }} e @ E {{ Φ }}  ( v, {{ Φ v }} K (of_val v) @ E {{ Φ' }})
83
   {{ P }} K e @ E {{ Φ' }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
84
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
85
  iIntros "[#Hwpe #HwpK] !# HP". iApply wp_bind.
Robbert Krebbers's avatar
Robbert Krebbers committed
86
  iApply wp_wand_r; iSplitL; [by iApply "Hwpe"|].
87
  iIntros (v) "Hv". by iApply "HwpK".
Robbert Krebbers's avatar
Robbert Krebbers committed
88
Qed.
89

90
Lemma ht_mask_weaken E1 E2 P Φ e :
91
  E1  E2  {{ P }} e @ E1 {{ Φ }}  {{ P }} e @ E2 {{ Φ }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
92
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
93
  iIntros (?) "#Hwp !# HP". iApply (wp_mask_mono E1 E2); try done.
Robbert Krebbers's avatar
Robbert Krebbers committed
94 95
  by iApply "Hwp".
Qed.
96

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

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

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

115 116
Lemma ht_frame_step_r E1 E2 P R1 R2 e Φ :
  to_val e = None  E2  E1 
117
  (R1 ={E1,E2}=>  |={E2,E1}=> R2)  {{ P }} e @ E2 {{ Φ }}
118
   {{ P  R1 }} e @ E1 {{ λ v, Φ v  R2 }}.
119
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
120
  iIntros (??) "[#Hvs #Hwp] !# [HP HR]".
121 122
  iApply (wp_frame_step_r E1 E2); try done.
  iSplitR "HR"; [by iApply "Hwp"|by iApply "Hvs"].
123 124
Qed.

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

Ralf Jung's avatar
Ralf Jung committed
133
Lemma ht_frame_step_r' E P Φ R e :
Robbert Krebbers's avatar
Robbert Krebbers committed
134
  to_val e = None 
135
  {{ P }} e @ E {{ Φ }}  {{ P   R }} e @ E {{ v, Φ v  R }}.
Robbert Krebbers's avatar
Robbert Krebbers committed
136
Proof.
Robbert Krebbers's avatar
Robbert Krebbers committed
137
  iIntros (?) "#Hwp !# [HP HR]".
Ralf Jung's avatar
Ralf Jung committed
138
  iApply wp_frame_step_r'; try done. iFrame "HR". by iApply "Hwp".
Robbert Krebbers's avatar
Robbert Krebbers committed
139
Qed.
140
End hoare.