-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathghost_var.v
61 lines (51 loc) · 2.33 KB
/
ghost_var.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(* Modified version supporting persistent ghost vars. *)
From iris.algebra Require Import dfrac_agree.
From iris.proofmode Require Import proofmode.
From iris.base_logic.lib Require Export own ghost_var.
From iris.prelude Require Import options.
Local Existing Instance ghost_var_inG.
Local Definition persistent_ghost_var_def `{!ghost_varG Σ A}
(γ : gname) (a : A) : iProp Σ :=
own γ (to_dfrac_agree (A:=leibnizO A) (DfracDiscarded) a).
Local Definition persistent_ghost_var_aux : seal (@persistent_ghost_var_def). Proof. by eexists. Qed.
Definition persistent_ghost_var := persistent_ghost_var_aux.(unseal).
Local Definition persistent_ghost_var_unseal :
@persistent_ghost_var = @persistent_ghost_var_def := persistent_ghost_var_aux.(seal_eq).
Global Arguments persistent_ghost_var {Σ A _} γ a.
Local Ltac unseal := rewrite
?ghost_var.ghost_var_unseal /ghost_var.ghost_var_def
?persistent_ghost_var_unseal /persistent_ghost_var_def.
Section lemmas.
Context `{!ghost_varG Σ A}.
Implicit Types (a b : A) (q : Qp).
Global Instance persistent_ghost_var_timeless γ a : Timeless (persistent_ghost_var γ a).
Proof. unseal. apply _. Qed.
Global Instance persistent_ghost_var_persistent γ a : Persistent (persistent_ghost_var γ a).
Proof. unseal. apply _. Qed.
(** Persistent ghost var rules *)
Lemma ghost_var_persist γ q a :
ghost_var γ q a ==∗ persistent_ghost_var γ a.
Proof. unseal. iApply own_update. apply dfrac_agree_persist. Qed.
Lemma persistent_ghost_var_valid_2 γ a1 a2 q2 :
persistent_ghost_var γ a1 -∗ ghost_var γ q2 a2 -∗ ⌜(q2 < 1)%Qp ∧ a1 = a2⌝.
Proof.
unseal. iIntros "Hvar1 Hvar2".
iCombine "Hvar1 Hvar2" gives %[Hq Ha]%dfrac_agree_op_valid_L.
done.
Qed.
(** Almost all the time, this is all you really need. *)
Lemma persistent_ghost_var_agree γ a1 a2 q2 :
persistent_ghost_var γ a1 -∗ ghost_var γ q2 a2 -∗ ⌜a1 = a2⌝.
Proof.
iIntros "Hvar1 Hvar2".
iDestruct (persistent_ghost_var_valid_2 with "Hvar1 Hvar2") as %[_ ?]. done.
Qed.
Global Instance ghost_var_combine_gives γ a1 a2 q2 :
CombineSepGives (persistent_ghost_var γ a1) (ghost_var γ q2 a2)
⌜(q2 < 1)%Qp ∧ a1 = a2⌝.
Proof.
rewrite /CombineSepGives. iIntros "[H1 H2]".
iDestruct (persistent_ghost_var_valid_2 with "H1 H2") as %[H1 H2].
eauto.
Qed.
End lemmas.