Commit 5696cb01 authored by Robbert Krebbers's avatar Robbert Krebbers

More CMRAs

* Framepreserving updates are now on CMRAs rather than RAs
* Excl and auth are now CMRAs
* Show that excl and auth are functors
* STS is now an CMRA
parent 780f6b82
Require Export iris.excl. Require Export iris.excl.
Local Arguments disjoint _ _ !_ !_ /. Local Arguments valid _ _ !_ /.
Local Arguments validN _ _ _ !_ /.
Record auth (A : Type) : Type := Auth { authoritative : excl A ; own : A }. Record auth (A : Type) : Type := Auth { authoritative : excl A ; own : A }.
Arguments Auth {_} _ _. Arguments Auth {_} _ _.
...@@ -8,11 +9,54 @@ Arguments own {_} _. ...@@ -8,11 +9,54 @@ Arguments own {_} _.
Notation "∘ x" := (Auth ExclUnit x) (at level 20). Notation "∘ x" := (Auth ExclUnit x) (at level 20).
Notation "∙ x" := (Auth (Excl x) ) (at level 20). Notation "∙ x" := (Auth (Excl x) ) (at level 20).
Instance auth_empty `{Empty A} : Empty (auth A) := Auth . (* COFE *)
Instance auth_valid `{Equiv A, Valid A, Op A} : Valid (auth A) := λ x,
valid (authoritative x) excl_above (own x) (authoritative x).
Instance auth_equiv `{Equiv A} : Equiv (auth A) := λ x y, Instance auth_equiv `{Equiv A} : Equiv (auth A) := λ x y,
authoritative x authoritative y own x own y. authoritative x authoritative y own x own y.
Instance auth_dist `{Dist A} : Dist (auth A) := λ n x y,
authoritative x ={n}= authoritative y own x ={n}= own y.
Instance Auth_ne `{Dist A} : Proper (dist n ==> dist n ==> dist n) (@Auth A).
Proof. by split. Qed.
Instance authoritative_ne `{Dist A} :
Proper (dist n ==> dist n) (@authoritative A).
Proof. by destruct 1. Qed.
Instance own_ne `{Dist A} : Proper (dist n ==> dist n) (@own A).
Proof. by destruct 1. Qed.
Instance auth_compl `{Cofe A} : Compl (auth A) := λ c,
Auth (compl (chain_map authoritative c)) (compl (chain_map own c)).
Local Instance auth_cofe `{Cofe A} : Cofe (auth A).
Proof.
split.
* intros x y; unfold dist, auth_dist, equiv, auth_equiv.
rewrite !equiv_dist; naive_solver.
* intros n; split.
+ by intros ?; split.
+ by intros ?? [??]; split; symmetry.
+ intros ??? [??] [??]; split; etransitivity; eauto.
* by intros n [x1 y1] [x2 y2] [??]; split; apply dist_S.
* by split.
* intros c n; split. apply (conv_compl (chain_map authoritative c) n).
apply (conv_compl (chain_map own c) n).
Qed.
(* CMRA *)
Instance auth_empty `{Empty A} : Empty (auth A) := Auth .
Instance auth_valid `{Equiv A, Valid A, Op A} : Valid (auth A) := λ x,
match authoritative x with
| Excl a => own x a valid a
| ExclUnit => valid (own x)
| ExclBot => False
end.
Arguments auth_valid _ _ _ _ !_ /.
Instance auth_validN `{Dist A, ValidN A, Op A} : ValidN (auth A) := λ n x,
match authoritative x with
| Excl a => own x {n} a validN n a
| ExclUnit => validN n (own x)
| ExclBot => n = 0
end.
Arguments auth_validN _ _ _ _ _ !_ /.
Instance auth_unit `{Unit A} : Unit (auth A) := λ x, Instance auth_unit `{Unit A} : Unit (auth A) := λ x,
Auth (unit (authoritative x)) (unit (own x)). Auth (unit (authoritative x)) (unit (own x)).
Instance auth_op `{Op A} : Op (auth A) := λ x y, Instance auth_op `{Op A} : Op (auth A) := λ x y,
...@@ -25,32 +69,82 @@ Proof. ...@@ -25,32 +69,82 @@ Proof.
split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|]. split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|].
intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto. intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto.
Qed. Qed.
Lemma auth_includedN `{Dist A, Op A} n (x y : auth A) :
Instance auth_ra `{RA A} : RA (auth A). x {n} y authoritative x {n} authoritative y own x {n} own y.
Proof.
split; [intros [[z1 z2] Hz]; split; [exists z1|exists z2]; apply Hz|].
intros [[z1 Hz1] [z2 Hz2]]; exists (Auth z1 z2); split; auto.
Qed.
Lemma authoritative_validN `{CMRA A} n (x : auth A) :
validN n x validN n (authoritative x).
Proof. by destruct x as [[]]. Qed.
Lemma own_validN `{CMRA A} n (x : auth A) : validN n x validN n (own x).
Proof. destruct x as [[]]; naive_solver eauto using cmra_valid_includedN. Qed.
Instance auth_cmra `{CMRA A} : CMRA (auth A).
Proof. Proof.
split. split.
* split. * apply _.
+ by intros ?; split. * by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy, ?Hy'.
+ by intros ?? [??]; split. * by intros n y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy, ?Hy'.
+ intros ??? [??] [??]; split; etransitivity; eauto. * intros n [x a] [y b] [Hx Ha]; simpl in *;
* by intros x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy, ?Hy'. destruct Hx as [[][]| | |]; intros ?; cofe_subst; auto.
* by intros y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy, ?Hy'. * by intros n x1 x2 [Hx Hx'] y1 y2 [Hy Hy'];
* by intros y1 y2 [Hy Hy'] [??]; split; simpl; rewrite <-?Hy, <-?Hy'.
* by intros x1 x2 [Hx Hx'] y1 y2 [Hy Hy'];
split; simpl; rewrite ?Hy, ?Hy', ?Hx, ?Hx'. split; simpl; rewrite ?Hy, ?Hy', ?Hx, ?Hx'.
* by intros [[] ?]; simpl.
* intros n [[] ?] ?; naive_solver eauto using cmra_included_S, cmra_valid_S.
* destruct x as [[a| |] b]; simpl; rewrite ?cmra_included_includedN,
?cmra_valid_validN; [naive_solver|naive_solver|].
split; [done|intros Hn; discriminate (Hn 1)].
* by split; simpl; rewrite (associative _). * by split; simpl; rewrite (associative _).
* by split; simpl; rewrite (commutative _). * by split; simpl; rewrite (commutative _).
* by split; simpl; rewrite ?(ra_unit_l _). * by split; simpl; rewrite ?(ra_unit_l _).
* by split; simpl; rewrite ?(ra_unit_idempotent _). * by split; simpl; rewrite ?(ra_unit_idempotent _).
* intros ??; rewrite! auth_included; intros [??]. * intros n ??; rewrite! auth_includedN; intros [??].
by split; simpl; apply ra_unit_preserving. by split; simpl; apply cmra_unit_preserving.
* intros ?? [??]; split; [by apply ra_valid_op_l with (authoritative y)|]. * assert ( n a b1 b2, b1 b2 {n} a b1 {n} a).
by apply excl_above_weaken with (own x own y) { intros n a b1 b2 <-; apply cmra_included_l. }
(authoritative x authoritative y); try apply ra_included_l. intros n [[a1| |] b1] [[a2| |] b2];
* by intros ??; rewrite auth_included; naive_solver eauto using cmra_valid_op_l, cmra_valid_includedN.
intros [??]; split; simpl; apply ra_op_minus. * by intros n ??; rewrite auth_includedN;
Qed. intros [??]; split; simpl; apply cmra_op_minus.
Instance auth_ra_empty `{RA A, Empty A, !RAEmpty A} : RAEmpty (auth A). Qed.
Proof. split. done. by intros x; constructor; simpl; rewrite (left_id _ _). Qed. Instance auth_cmra_extend `{CMRA A, !CMRAExtend A} : CMRAExtend (auth A).
Lemma auth_frag_op `{RA A} a b : (a b) a b. Proof.
Proof. done. Qed. intros n x y1 y2 ? [??]; simpl in *.
\ No newline at end of file destruct (cmra_extend_op n (authoritative x) (authoritative y1)
(authoritative y2)) as (z1&?&?&?); auto using authoritative_validN.
destruct (cmra_extend_op n (own x) (own y1) (own y2))
as (z2&?&?&?); auto using own_validN.
by exists (Auth (z1.1) (z2.1), Auth (z1.2) (z2.2)).
Qed.
Instance auth_ra_empty `{CMRA A, Empty A, !RAEmpty A} : RAEmpty (auth A).
Proof.
split; [apply (ra_empty_valid (A:=A))|].
by intros x; constructor; simpl; rewrite (left_id _ _).
Qed.
Lemma auth_frag_op `{CMRA A} a b : (a b) a b.
Proof. done. Qed.
(* Functor *)
Definition authRA (A : cmraT) : cmraT := CMRAT (auth A).
Instance auth_fmap : FMap auth := λ A B f x,
Auth (f <$> authoritative x) (f (own x)).
Instance auth_fmap_cmra_ne `{Dist A, Dist B} n :
Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@fmap auth _ A B).
Proof.
intros f g Hf [??] [??] [??]; split; [by apply excl_fmap_cmra_ne|by apply Hf].
Qed.
Instance auth_fmap_cmra_monotone `{CMRA A, CMRA B} (f : A B) :
( n, Proper (dist n ==> dist n) f) CMRAMonotone f
CMRAMonotone (fmap f : auth A auth B).
Proof.
split.
* by intros n [x a] [y b]; rewrite !auth_includedN; simpl;
intros [??]; split; apply includedN_preserving.
* intros n [[a| |] b];
naive_solver eauto using @includedN_preserving, @validN_preserving.
Qed.
Definition authRA_map {A B : cmraT} (f : A -n> B) : authRA A -n> authRA B :=
CofeMor (fmap f : authRA A authRA B).
Lemma authRA_map_ne A B n : Proper (dist n ==> dist n) (@authRA_map A B).
Proof. intros f f' Hf [[a| |] b]; repeat constructor; apply Hf. Qed.
...@@ -7,6 +7,7 @@ Definition includedN `{Dist A, Op A} (n : nat) (x y : A) := ∃ z, y ={n}= x ⋅ ...@@ -7,6 +7,7 @@ Definition includedN `{Dist A, Op A} (n : nat) (x y : A) := ∃ z, y ={n}= x ⋅
Notation "x ≼{ n } y" := (includedN n x y) Notation "x ≼{ n } y" := (includedN n x y)
(at level 70, format "x ≼{ n } y") : C_scope. (at level 70, format "x ≼{ n } y") : C_scope.
Instance: Params (@includedN) 4. Instance: Params (@includedN) 4.
Hint Extern 0 (?x {_} ?x) => reflexivity.
Class CMRA A `{Equiv A, Compl A, Unit A, Op A, Valid A, ValidN A, Minus A} := { Class CMRA A `{Equiv A, Compl A, Unit A, Op A, Valid A, ValidN A, Minus A} := {
(* setoids *) (* setoids *)
...@@ -38,6 +39,8 @@ Class CMRAMonotone ...@@ -38,6 +39,8 @@ Class CMRAMonotone
validN_preserving n x : validN n x validN n (f x) validN_preserving n x : validN n x validN n (f x)
}. }.
Hint Extern 0 (validN 0 _) => apply cmra_valid_0.
(** Bundeled version *) (** Bundeled version *)
Structure cmraT := CMRAT { Structure cmraT := CMRAT {
cmra_car :> Type; cmra_car :> Type;
...@@ -69,6 +72,17 @@ Existing Instances cmra_equiv cmra_dist cmra_compl cmra_unit cmra_op ...@@ -69,6 +72,17 @@ Existing Instances cmra_equiv cmra_dist cmra_compl cmra_unit cmra_op
Coercion cmra_cofeC (A : cmraT) : cofeT := CofeT A. Coercion cmra_cofeC (A : cmraT) : cofeT := CofeT A.
Canonical Structure cmra_cofeC. Canonical Structure cmra_cofeC.
(** Updates *)
Definition cmra_updateP `{Op A, ValidN A} (x : A) (P : A Prop) :=
z n, validN n (x z) y, P y validN n (y z).
Instance: Params (@cmra_updateP) 3.
Infix "⇝:" := cmra_updateP (at level 70).
Definition cmra_update `{Op A, ValidN A} (x y : A) := z n,
validN n (x z) validN n (y z).
Infix "⇝" := cmra_update (at level 70).
Instance: Params (@cmra_update) 3.
(** Properties **)
Section cmra. Section cmra.
Context `{cmra : CMRA A}. Context `{cmra : CMRA A}.
Implicit Types x y z : A. Implicit Types x y z : A.
...@@ -80,9 +94,9 @@ Proof. ...@@ -80,9 +94,9 @@ Proof.
symmetry; apply cmra_op_minus, Hxy. symmetry; apply cmra_op_minus, Hxy.
Qed. Qed.
Global Instance cmra_valid_ne' : Proper (dist n ==> iff) (validN n). Global Instance cmra_valid_ne' : Proper (dist n ==> iff) (validN n) | 1.
Proof. by split; apply cmra_valid_ne. Qed. Proof. by split; apply cmra_valid_ne. Qed.
Global Instance cmra_valid_proper : Proper (() ==> iff) (validN n). Global Instance cmra_valid_proper : Proper (() ==> iff) (validN n) | 1.
Proof. by intros n x1 x2 Hx; apply cmra_valid_ne', equiv_dist. Qed. Proof. by intros n x1 x2 Hx; apply cmra_valid_ne', equiv_dist. Qed.
Global Instance cmra_ra : RA A. Global Instance cmra_ra : RA A.
Proof. Proof.
...@@ -118,12 +132,13 @@ Qed. ...@@ -118,12 +132,13 @@ Qed.
(** * Included *) (** * Included *)
Global Instance cmra_included_ne n : Global Instance cmra_included_ne n :
Proper (dist n ==> dist n ==> iff) (includedN n). Proper (dist n ==> dist n ==> iff) (includedN n) | 1.
Proof. Proof.
intros x x' Hx y y' Hy; unfold includedN. intros x x' Hx y y' Hy; unfold includedN.
by setoid_rewrite Hx; setoid_rewrite Hy. by setoid_rewrite Hx; setoid_rewrite Hy.
Qed. Qed.
Global Instance cmra_included_proper:Proper (() ==> () ==> iff) (includedN n). Global Instance cmra_included_proper :
Proper (() ==> () ==> iff) (includedN n) | 1.
Proof. Proof.
intros n x x' Hx y y' Hy; unfold includedN. intros n x x' Hx y y' Hy; unfold includedN.
by setoid_rewrite Hx; setoid_rewrite Hy. by setoid_rewrite Hx; setoid_rewrite Hy.
...@@ -154,6 +169,16 @@ Proof. ...@@ -154,6 +169,16 @@ Proof.
intros [z Hx2] Hx1; exists (x1' z); split; auto using ra_included_l. intros [z Hx2] Hx1; exists (x1' z); split; auto using ra_included_l.
by rewrite Hx1, Hx2. by rewrite Hx1, Hx2.
Qed. Qed.
(** * Properties of [(⇝)] relation *)
Global Instance cmra_update_preorder : PreOrder cmra_update.
Proof. split. by intros x y. intros x y y' ?? z ?; naive_solver. Qed.
Lemma cmra_update_updateP x y : x y x : (y =).
Proof.
split.
* by intros Hx z ?; exists y; split; [done|apply (Hx z)].
* by intros Hx z n ?; destruct (Hx z n) as (?&<-&?).
Qed.
End cmra. End cmra.
Instance cmra_monotone_id `{CMRA A} : CMRAMonotone (@id A). Instance cmra_monotone_id `{CMRA A} : CMRAMonotone (@id A).
...@@ -168,6 +193,7 @@ Proof. ...@@ -168,6 +193,7 @@ Proof.
by intros ? n; apply validN_preserving. by intros ? n; apply validN_preserving.
Qed. Qed.
Hint Extern 0 (_ {0} _) => apply cmra_included_0.
(* Also via [cmra_cofe; cofe_equivalence] *) (* Also via [cmra_cofe; cofe_equivalence] *)
Hint Cut [!*; ra_equivalence; cmra_ra] : typeclass_instances. Hint Cut [!*; ra_equivalence; cmra_ra] : typeclass_instances.
...@@ -197,6 +223,15 @@ Section discrete. ...@@ -197,6 +223,15 @@ Section discrete.
by exists (x,unit x); simpl; rewrite ra_unit_r. by exists (x,unit x); simpl; rewrite ra_unit_r.
Qed. Qed.
Definition discreteRA : cmraT := CMRAT A. Definition discreteRA : cmraT := CMRAT A.
Lemma discrete_updateP (x : A) (P : A Prop) `{!Inhabited (sig P)} :
( z, valid (x z) y, P y valid (y z)) x : P.
Proof.
intros Hvalid z [|n]; [|apply Hvalid].
by destruct (_ : Inhabited (sig P)) as [[y ?]]; exists y.
Qed.
Lemma discrete_update (x y : A) :
( z, valid (x z) valid (y z)) x y.
Proof. intros Hvalid z [|n]; [done|apply Hvalid]. Qed.
End discrete. End discrete.
Arguments discreteRA _ {_ _ _ _ _ _}. Arguments discreteRA _ {_ _ _ _ _ _}.
......
...@@ -66,7 +66,7 @@ Proof. ...@@ -66,7 +66,7 @@ Proof.
* by exists (None,Some x); inversion Hx'; repeat constructor. * by exists (None,Some x); inversion Hx'; repeat constructor.
* exists (None,None); repeat constructor. * exists (None,None); repeat constructor.
Qed. Qed.
Instance option_fmap_cmra_preserving `{CMRA A, CMRA B} (f : A B) Instance option_fmap_cmra_monotone `{CMRA A, CMRA B} (f : A B)
`{!CMRAMonotone f} : CMRAMonotone (fmap f : option A option B). `{!CMRAMonotone f} : CMRAMonotone (fmap f : option A option B).
Proof. Proof.
split. split.
...@@ -169,7 +169,7 @@ Section map. ...@@ -169,7 +169,7 @@ Section map.
CofeMor (fmap f : mapRA A mapRA B). CofeMor (fmap f : mapRA A mapRA B).
Global Instance mapRA_map_ne {A B} n : Global Instance mapRA_map_ne {A B} n :
Proper (dist n ==> dist n) (@mapRA_map A B) := mapC_map_ne n. Proper (dist n ==> dist n) (@mapRA_map A B) := mapC_map_ne n.
Global Instance mapRA_mapcmra_monotone {A B : cmraT} (f : A -n> B) Global Instance mapRA_map_monotone {A B : cmraT} (f : A -n> B)
`{!CMRAMonotone f} : CMRAMonotone (mapRA_map f) := _. `{!CMRAMonotone f} : CMRAMonotone (mapRA_map f) := _.
End map. End map.
......
...@@ -97,6 +97,12 @@ Section cofe. ...@@ -97,6 +97,12 @@ Section cofe.
Proper (() ==> ()) f | 100 := _. Proper (() ==> ()) f | 100 := _.
End cofe. End cofe.
(** Mapping a chain *)
Program Definition chain_map `{Dist A, Dist B} (f : A B)
`{! n, Proper (dist n ==> dist n) f} (c : chain A) : chain B :=
{| chain_car n := f (c n) |}.
Next Obligation. by intros A ? B ? f Hf c n i ?; apply Hf, chain_cauchy. Qed.
(** Timeless elements *) (** Timeless elements *)
Class Timeless `{Dist A, Equiv A} (x : A) := timeless y : x ={1}= y x y. Class Timeless `{Dist A, Equiv A} (x : A) := timeless y : x ={1}= y x y.
Arguments timeless {_ _ _} _ {_} _ _. Arguments timeless {_ _ _} _ {_} _ _.
...@@ -212,14 +218,12 @@ Proof. by repeat split; try exists 0. Qed. ...@@ -212,14 +218,12 @@ Proof. by repeat split; try exists 0. Qed.
(** Product *) (** Product *)
Instance prod_dist `{Dist A, Dist B} : Dist (A * B) := λ n, Instance prod_dist `{Dist A, Dist B} : Dist (A * B) := λ n,
prod_relation (dist n) (dist n). prod_relation (dist n) (dist n).
Program Definition fst_chain `{Dist A, Dist B} (c : chain (A * B)) : chain A := Instance pair_ne `{Dist A, Dist B} :
{| chain_car n := fst (c n) |}. Proper (dist n ==> dist n ==> dist n) (@pair A B) := _.
Next Obligation. by intros A ? B ? c n i ?; apply (chain_cauchy c n). Qed. Instance fst_ne `{Dist A, Dist B} : Proper (dist n ==> dist n) (@fst A B) := _.
Program Definition snd_chain `{Dist A, Dist B} (c : chain (A * B)) : chain B := Instance snd_ne `{Dist A, Dist B} : Proper (dist n ==> dist n) (@snd A B) := _.
{| chain_car n := snd (c n) |}.
Next Obligation. by intros A ? B ? c n i ?; apply (chain_cauchy c n). Qed.
Instance prod_compl `{Compl A, Compl B} : Compl (A * B) := λ c, Instance prod_compl `{Compl A, Compl B} : Compl (A * B) := λ c,
(compl (fst_chain c), compl (snd_chain c)). (compl (chain_map fst c), compl (chain_map snd c)).
Instance prod_cofe `{Cofe A, Cofe B} : Cofe (A * B). Instance prod_cofe `{Cofe A, Cofe B} : Cofe (A * B).
Proof. Proof.
split. split.
...@@ -228,8 +232,8 @@ Proof. ...@@ -228,8 +232,8 @@ Proof.
* apply _. * apply _.
* by intros n [x1 y1] [x2 y2] [??]; split; apply dist_S. * by intros n [x1 y1] [x2 y2] [??]; split; apply dist_S.
* by split. * by split.
* intros c n; split. apply (conv_compl (fst_chain c) n). * intros c n; split. apply (conv_compl (chain_map fst c) n).
apply (conv_compl (snd_chain c) n). apply (conv_compl (chain_map snd c) n).
Qed. Qed.
Instance pair_timeless `{Dist A, Equiv A, Dist B, Equiv B} (x : A) (y : B) : Instance pair_timeless `{Dist A, Equiv A, Dist B, Equiv B} (x : A) (y : B) :
Timeless x Timeless y Timeless (x,y). Timeless x Timeless y Timeless (x,y).
...@@ -245,10 +249,6 @@ Instance prodC_map_ne {A A' B B'} n : ...@@ -245,10 +249,6 @@ Instance prodC_map_ne {A A' B B'} n :
Proper (dist n ==> dist n ==> dist n) (@prodC_map A A' B B'). Proper (dist n ==> dist n ==> dist n) (@prodC_map A A' B B').
Proof. intros f f' Hf g g' Hg [??]; split; [apply Hf|apply Hg]. Qed. Proof. intros f f' Hf g g' Hg [??]; split; [apply Hf|apply Hg]. Qed.
Instance pair_ne `{Dist A, Dist B} :
Proper (dist n ==> dist n ==> dist n) (@pair A B) := _.
Instance fst_ne `{Dist A, Dist B} : Proper (dist n ==> dist n) (@fst A B) := _.
Instance snd_ne `{Dist A, Dist B} : Proper (dist n ==> dist n) (@snd A B) := _.
Typeclasses Opaque prod_dist. Typeclasses Opaque prod_dist.
(** Discrete cofe *) (** Discrete cofe *)
...@@ -268,11 +268,11 @@ Section discrete_cofe. ...@@ -268,11 +268,11 @@ Section discrete_cofe.
Qed. Qed.
Global Instance discrete_timeless (x : A) : Timeless x. Global Instance discrete_timeless (x : A) : Timeless x.
Proof. by intros y. Qed. Proof. by intros y. Qed.
Definition discrete_cofeC : cofeT := CofeT A. Definition discreteC : cofeT := CofeT A.
End discrete_cofe. End discrete_cofe.
Arguments discrete_cofeC _ {_ _}. Arguments discreteC _ {_ _}.
Definition leibniz_cofeC (A : Type) : cofeT := @discrete_cofeC A equivL _. Definition leibnizC (A : Type) : cofeT := @discreteC A equivL _.
(** Later *) (** Later *)
Inductive later (A : Type) : Type := Later { later_car : A }. Inductive later (A : Type) : Type := Later { later_car : A }.
......
Require Export iris.ra. Require Export iris.ra iris.cmra.
(** From disjoint pcm *) (** From disjoint pcm *)
Record validity {A} (P : A Prop) : Type := Validity { Record validity {A} (P : A Prop) : Type := Validity {
...@@ -88,17 +88,20 @@ Hint Immediate dra_disjoint_move_l dra_disjoint_move_r. ...@@ -88,17 +88,20 @@ Hint Immediate dra_disjoint_move_l dra_disjoint_move_r.
Hint Unfold dra_included. Hint Unfold dra_included.
Notation T := (validity (valid : A Prop)). Notation T := (validity (valid : A Prop)).
Lemma validity_valid_car_valid (z : T) : V z V (validity_car z).
Proof. apply validity_prf. Qed.
Hint Resolve validity_valid_car_valid.
Program Instance validity_unit : Unit T := λ x, Program Instance validity_unit : Unit T := λ x,
Validity (unit (validity_car x)) (V x) _. Validity (unit (validity_car x)) (V x) _.
Next Obligation. by apply dra_unit_valid, validity_prf. Qed. Solve Obligations with naive_solver auto using dra_unit_valid.
Program Instance validity_op : Op T := λ x y, Program Instance validity_op : Op T := λ x y,
Validity (validity_car x validity_car y) Validity (validity_car x validity_car y)
(V x V y validity_car x validity_car y) _. (V x V y validity_car x validity_car y) _.
Next Obligation. by apply dra_op_valid; try apply validity_prf. Qed. Solve Obligations with naive_solver auto using dra_op_valid.
Program Instance validity_minus : Minus T := λ x y, Program Instance validity_minus : Minus T := λ x y,
Validity (validity_car x validity_car y) Validity (validity_car x validity_car y)
(V x V y validity_car y validity_car x) _. (V x V y validity_car y validity_car x) _.
Next Obligation. by apply dra_minus_valid; try apply validity_prf. Qed. Solve Obligations with naive_solver auto using dra_minus_valid.
Instance validity_ra : RA T. Instance validity_ra : RA T.
Proof. Proof.
split. split.
...@@ -130,10 +133,11 @@ Proof. ...@@ -130,10 +133,11 @@ Proof.
* intros [x px ?] [y py ?] [[z pz ?] [??]]; split; simpl in *; * intros [x px ?] [y py ?] [[z pz ?] [??]]; split; simpl in *;
intuition eauto 10 using dra_disjoint_minus, dra_op_minus. intuition eauto 10 using dra_disjoint_minus, dra_op_minus.
Qed. Qed.
Definition dra_update (x y : T) : Definition validityRA : cmraT := discreteRA T.
Definition validity_update (x y : validityRA) :
( z, V x V z validity_car x z V y validity_car y z) x y. ( z, V x V z validity_car x z V y validity_car y z) x y.
Proof. Proof.
intros Hxy z (?&?&?); split_ands'; auto; intros Hxy; apply discrete_update.
eapply Hxy; eauto; by eapply validity_prf. intros z (?&?&?); split_ands'; try eapply Hxy; eauto.
Qed. Qed.
End dra. End dra.
Require Export iris.cmra. Require Export iris.cmra.
Local Arguments disjoint _ _ !_ !_ /. Local Arguments validN _ _ _ !_ /.
Local Arguments valid _ _ !_ /.
Inductive excl (A : Type) := Inductive excl (A : Type) :=
| Excl : A excl A | Excl : A excl A
| ExclUnit : Empty (excl A) | ExclUnit : excl A
| ExclBot : excl A. | ExclBot : excl A.
Arguments Excl {_} _. Arguments Excl {_} _.
Arguments ExclUnit {_}. Arguments ExclUnit {_}.