Commit cfb00b3e authored by Robbert Krebbers's avatar Robbert Krebbers

CMRAs with partial cores.

Based on an idea and WIP commits of J-H. Jourdan: the core of a CMRA
A is now a partial function A → option A.

TODO: define sum CMRA
TODO: remove one shot CMRA and define it in terms of sum
parent 4195e15c
...@@ -60,7 +60,7 @@ Program Instance agree_op : Op (agree A) := λ x y, ...@@ -60,7 +60,7 @@ Program Instance agree_op : Op (agree A) := λ x y,
{| agree_car := x; {| agree_car := x;
agree_is_valid n := agree_is_valid x n agree_is_valid y n x {n} y |}. agree_is_valid n := agree_is_valid x n agree_is_valid y n x {n} y |}.
Next Obligation. naive_solver eauto using agree_valid_S, dist_S. Qed. Next Obligation. naive_solver eauto using agree_valid_S, dist_S. Qed.
Instance agree_core : Core (agree A) := id. Instance agree_pcore : PCore (agree A) := Some.
Instance: Comm () (@op (agree A) _). Instance: Comm () (@op (agree A) _).
Proof. intros x y; split; [naive_solver|by intros n (?&?&Hxy); apply Hxy]. Qed. Proof. intros x y; split; [naive_solver|by intros n (?&?&Hxy); apply Hxy]. Qed.
...@@ -106,11 +106,11 @@ Qed. ...@@ -106,11 +106,11 @@ Qed.
Definition agree_cmra_mixin : CMRAMixin (agree A). Definition agree_cmra_mixin : CMRAMixin (agree A).
Proof. Proof.
split; try (apply _ || done). apply cmra_total_mixin; try apply _ || by eauto.
- intros n x [? Hx]; split; [by apply agree_valid_S|intros n' ?]. - intros n x [? Hx]; split; [by apply agree_valid_S|intros n' ?].
rewrite -(Hx n'); last auto. rewrite -(Hx n'); last auto.
symmetry; apply dist_le with n; try apply Hx; auto. symmetry; apply dist_le with n; try apply Hx; auto.
- intros x; apply agree_idemp. - intros x. apply agree_idemp.
- by intros n x y [(?&?&?) ?]. - by intros n x y [(?&?&?) ?].
- intros n x y1 y2 Hval Hx; exists (x,x); simpl; split. - intros n x y1 y2 Hval Hx; exists (x,x); simpl; split.
+ by rewrite agree_idemp. + by rewrite agree_idemp.
...@@ -119,8 +119,10 @@ Qed. ...@@ -119,8 +119,10 @@ Qed.
Canonical Structure agreeR : cmraT := Canonical Structure agreeR : cmraT :=
CMRAT (agree A) agree_cofe_mixin agree_cmra_mixin. CMRAT (agree A) agree_cofe_mixin agree_cmra_mixin.
Global Instance agree_total : CMRATotal agreeR.
Proof. rewrite /CMRATotal; eauto. Qed.
Global Instance agree_persistent (x : agree A) : Persistent x. Global Instance agree_persistent (x : agree A) : Persistent x.
Proof. done. Qed. Proof. by constructor. Qed.
Program Definition to_agree (x : A) : agree A := Program Definition to_agree (x : A) : agree A :=
{| agree_car n := x; agree_is_valid n := True |}. {| agree_car n := x; agree_is_valid n := True |}.
......
...@@ -3,18 +3,18 @@ From iris.algebra Require Import upred. ...@@ -3,18 +3,18 @@ From iris.algebra Require Import upred.
Local Arguments valid _ _ !_ /. Local Arguments valid _ _ !_ /.
Local Arguments validN _ _ _ !_ /. Local Arguments validN _ _ _ !_ /.
Record auth (A : Type) : Type := Auth { authoritative : excl A ; own : A }. Record auth (A : Type) := Auth { authoritative : option (excl A); own : A }.
Add Printing Constructor auth. Add Printing Constructor auth.
Arguments Auth {_} _ _. Arguments Auth {_} _ _.
Arguments authoritative {_} _. Arguments authoritative {_} _.
Arguments own {_} _. Arguments own {_} _.
Notation "◯ a" := (Auth ExclUnit a) (at level 20). Notation "◯ a" := (Auth None a) (at level 20).
Notation "● a" := (Auth (Excl a) ) (at level 20). Notation "● a" := (Auth (Excl' a) ) (at level 20).
(* COFE *) (* COFE *)
Section cofe. Section cofe.
Context {A : cofeT}. Context {A : cofeT}.
Implicit Types a : excl A. Implicit Types a : option (excl A).
Implicit Types b : A. Implicit Types b : A.
Implicit Types x y : auth A. Implicit Types x y : auth A.
...@@ -72,20 +72,20 @@ Implicit Types x y : auth A. ...@@ -72,20 +72,20 @@ Implicit Types x y : auth A.
Instance auth_valid : Valid (auth A) := λ x, Instance auth_valid : Valid (auth A) := λ x,
match authoritative x with match authoritative x with
| Excl a => ( n, own x {n} a) a | Excl' a => ( n, own x {n} a) a
| ExclUnit => own x | None => own x
| ExclBot => False | ExclBot' => False
end. end.
Global Arguments auth_valid !_ /. Global Arguments auth_valid !_ /.
Instance auth_validN : ValidN (auth A) := λ n x, Instance auth_validN : ValidN (auth A) := λ n x,
match authoritative x with match authoritative x with
| Excl a => own x {n} a {n} a | Excl' a => own x {n} a {n} a
| ExclUnit => {n} own x | None => {n} own x
| ExclBot => False | ExclBot' => False
end. end.
Global Arguments auth_validN _ !_ /. Global Arguments auth_validN _ !_ /.
Instance auth_core : Core (auth A) := λ x, Instance auth_pcore : PCore (auth A) := λ x,
Auth (core (authoritative x)) (core (own x)). Some (Auth (core (authoritative x)) (core (own x))).
Instance auth_op : Op (auth A) := λ x y, Instance auth_op : Op (auth A) := λ x y,
Auth (authoritative x authoritative y) (own x own y). Auth (authoritative x authoritative y) (own x own y).
...@@ -96,20 +96,21 @@ Proof. ...@@ -96,20 +96,21 @@ Proof.
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 authoritative_validN n (x : auth A) : {n} x {n} authoritative x. Lemma authoritative_validN n (x : auth A) : {n} x {n} authoritative x.
Proof. by destruct x as [[]]. Qed. Proof. by destruct x as [[[]|]]. Qed.
Lemma own_validN n (x : auth A) : {n} x {n} own x. Lemma own_validN n (x : auth A) : {n} x {n} own x.
Proof. destruct x as [[]]; naive_solver eauto using cmra_validN_includedN. Qed. Proof. destruct x as [[[]|]]; naive_solver eauto using cmra_validN_includedN. Qed.
Lemma auth_cmra_mixin : CMRAMixin (auth A). Lemma auth_cmra_mixin : CMRAMixin (auth A).
Proof. Proof.
split. apply cmra_total_mixin.
- eauto.
- by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'. - by intros n x y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'.
- by intros n y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'. - by intros n y1 y2 [Hy Hy']; split; simpl; rewrite ?Hy ?Hy'.
- intros n [x a] [y b] [Hx Ha]; simpl in *; - intros n [x a] [y b] [Hx Ha]; simpl in *.
destruct Hx; intros ?; cofe_subst; auto. destruct Hx as [?? Hx|]; first destruct Hx; intros ?; cofe_subst; auto.
- intros [[] ?]; rewrite /= ?cmra_included_includedN ?cmra_valid_validN; - intros [[[?|]|] ?]; rewrite /= ?cmra_included_includedN ?cmra_valid_validN;
naive_solver eauto using O. naive_solver eauto using O.
- intros n [[] ?] ?; naive_solver eauto using cmra_includedN_S, cmra_validN_S. - intros n [[[]|] ?] ?; naive_solver eauto using cmra_includedN_S, cmra_validN_S.
- by split; simpl; rewrite assoc. - by split; simpl; rewrite assoc.
- by split; simpl; rewrite comm. - by split; simpl; rewrite comm.
- by split; simpl; rewrite ?cmra_core_l. - by split; simpl; rewrite ?cmra_core_l.
...@@ -118,7 +119,7 @@ Proof. ...@@ -118,7 +119,7 @@ Proof.
by split; simpl; apply cmra_core_preserving. by split; simpl; apply cmra_core_preserving.
- assert ( n (a b1 b2 : A), b1 b2 {n} a b1 {n} a). - assert ( n (a b1 b2 : A), b1 b2 {n} a b1 {n} a).
{ intros n a b1 b2 <-; apply cmra_includedN_l. } { intros n a b1 b2 <-; apply cmra_includedN_l. }
intros n [[a1| |] b1] [[a2| |] b2]; intros n [[[a1|]|] b1] [[[a2|]|] b2];
naive_solver eauto using cmra_validN_op_l, cmra_validN_includedN. naive_solver eauto using cmra_validN_op_l, cmra_validN_includedN.
- intros n x y1 y2 ? [??]; simpl in *. - intros n x y1 y2 ? [??]; simpl in *.
destruct (cmra_extend n (authoritative x) (authoritative y1) destruct (cmra_extend n (authoritative x) (authoritative y1)
...@@ -127,12 +128,12 @@ Proof. ...@@ -127,12 +128,12 @@ Proof.
as (b&?&?&?); auto using own_validN. as (b&?&?&?); auto using own_validN.
by exists (Auth (ea.1) (b.1), Auth (ea.2) (b.2)). by exists (Auth (ea.1) (b.1), Auth (ea.2) (b.2)).
Qed. Qed.
Canonical Structure authR := Canonical Structure authR := CMRAT (auth A) auth_cofe_mixin auth_cmra_mixin.
CMRAT (auth A) auth_cofe_mixin auth_cmra_mixin.
Global Instance auth_cmra_discrete : CMRADiscrete A CMRADiscrete authR. Global Instance auth_cmra_discrete : CMRADiscrete A CMRADiscrete authR.
Proof. Proof.
split; first apply _. split; first apply _.
intros [[] ?]; rewrite /= /cmra_valid /cmra_validN /=; auto. intros [[[?|]|] ?]; rewrite /= /cmra_valid /cmra_validN /=; auto.
- setoid_rewrite <-cmra_discrete_included_iff. - setoid_rewrite <-cmra_discrete_included_iff.
rewrite -cmra_discrete_valid_iff. tauto. rewrite -cmra_discrete_valid_iff. tauto.
- by rewrite -cmra_discrete_valid_iff. - by rewrite -cmra_discrete_valid_iff.
...@@ -145,6 +146,7 @@ Proof. ...@@ -145,6 +146,7 @@ Proof.
- apply (@ucmra_unit_valid A). - apply (@ucmra_unit_valid A).
- by intros x; constructor; rewrite /= left_id. - by intros x; constructor; rewrite /= left_id.
- apply _. - apply _.
- do 2 constructor; simpl; apply (persistent_core _).
Qed. Qed.
Canonical Structure authUR := Canonical Structure authUR :=
UCMRAT (auth A) auth_cofe_mixin auth_cmra_mixin auth_ucmra_mixin. UCMRAT (auth A) auth_cofe_mixin auth_cmra_mixin auth_ucmra_mixin.
...@@ -155,22 +157,23 @@ Lemma auth_equivI {M} (x y : auth A) : ...@@ -155,22 +157,23 @@ Lemma auth_equivI {M} (x y : auth A) :
Proof. by uPred.unseal. Qed. Proof. by uPred.unseal. Qed.
Lemma auth_validI {M} (x : auth A) : Lemma auth_validI {M} (x : auth A) :
( x) (match authoritative x with ( x) (match authoritative x with
| Excl a => ( b, a own x b) a | Excl' a => ( b, a own x b) a
| ExclUnit => own x | None => own x
| ExclBot => False | ExclBot' => False
end : uPred M). end : uPred M).
Proof. uPred.unseal. by destruct x as [[]]. Qed. Proof. uPred.unseal. by destruct x as [[[]|]]. Qed.
Lemma auth_frag_op a b : (a b) a b. Lemma auth_frag_op a b : (a b) a b.
Proof. done. Qed. Proof. done. Qed.
Lemma auth_both_op a b : Auth (Excl a) b a b. Lemma auth_both_op a b : Auth (Excl' a) b a b.
Proof. by rewrite /op /auth_op /= left_id. Qed. Proof. by rewrite /op /auth_op /= left_id. Qed.
Lemma auth_update a a' b b' : Lemma auth_update a a' b b' :
( n af, {n} a a {n} a' af b {n} b' af {n} b) ( n af, {n} a a {n} a' af b {n} b' af {n} b)
a a' ~~> b b'. a a' ~~> b b'.
Proof. Proof.
move=> Hab n [[?| |] bf1] // =>-[[bf2 Ha] ?]; do 2 red; simpl in *. intros Hab; apply cmra_total_update.
move=> n [[[?|]|] bf1] // =>-[[bf2 Ha] ?]; do 2 red; simpl in *.
destruct (Hab n (bf1 bf2)) as [Ha' ?]; auto. destruct (Hab n (bf1 bf2)) as [Ha' ?]; auto.
{ by rewrite Ha left_id assoc. } { by rewrite Ha left_id assoc. }
split; [by rewrite Ha' left_id assoc; apply cmra_includedN_l|done]. split; [by rewrite Ha' left_id assoc; apply cmra_includedN_l|done].
...@@ -209,25 +212,29 @@ Arguments authUR : clear implicits. ...@@ -209,25 +212,29 @@ Arguments authUR : clear implicits.
(* Functor *) (* Functor *)
Definition auth_map {A B} (f : A B) (x : auth A) : auth B := Definition auth_map {A B} (f : A B) (x : auth A) : auth B :=
Auth (excl_map f (authoritative x)) (f (own x)). Auth (excl_map f <$> authoritative x) (f (own x)).
Lemma auth_map_id {A} (x : auth A) : auth_map id x = x. Lemma auth_map_id {A} (x : auth A) : auth_map id x = x.
Proof. by destruct x; rewrite /auth_map excl_map_id. Qed. Proof. by destruct x as [[[]|]]. Qed.
Lemma auth_map_compose {A B C} (f : A B) (g : B C) (x : auth A) : Lemma auth_map_compose {A B C} (f : A B) (g : B C) (x : auth A) :
auth_map (g f) x = auth_map g (auth_map f x). auth_map (g f) x = auth_map g (auth_map f x).
Proof. by destruct x; rewrite /auth_map excl_map_compose. Qed. Proof. by destruct x as [[[]|]]. Qed.
Lemma auth_map_ext {A B : cofeT} (f g : A B) x : Lemma auth_map_ext {A B : cofeT} (f g : A B) x :
( x, f x g x) auth_map f x auth_map g x. ( x, f x g x) auth_map f x auth_map g x.
Proof. constructor; simpl; auto using excl_map_ext. Qed. Proof.
Instance auth_map_cmra_ne {A B : cofeT} n : constructor; simpl; auto.
apply option_fmap_setoid_ext=> a; by apply excl_map_ext.
Qed.
Instance auth_map_ne {A B : cofeT} n :
Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@auth_map A B). Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@auth_map A B).
Proof. Proof.
intros f g Hf [??] [??] [??]; split; [by apply excl_map_cmra_ne|by apply Hf]. intros f g Hf [??] [??] [??]; split; simpl in *; [|by apply Hf].
apply option_fmap_ne; [|done]=> x y ?; by apply excl_map_ne.
Qed. Qed.
Instance auth_map_cmra_monotone {A B : ucmraT} (f : A B) : Instance auth_map_cmra_monotone {A B : ucmraT} (f : A B) :
CMRAMonotone f CMRAMonotone (auth_map f). CMRAMonotone f CMRAMonotone (auth_map f).
Proof. Proof.
split; try apply _. split; try apply _.
- intros n [[a| |] b]; rewrite /= /cmra_validN /=; try - intros n [[[a|]|] b]; rewrite /= /cmra_validN /=; try
naive_solver eauto using includedN_preserving, validN_preserving. naive_solver eauto using includedN_preserving, validN_preserving.
- by intros [x a] [y b]; rewrite !auth_included /=; - by intros [x a] [y b]; rewrite !auth_included /=;
intros [??]; split; simpl; apply: included_preserving. intros [??]; split; simpl; apply: included_preserving.
...@@ -235,7 +242,7 @@ Qed. ...@@ -235,7 +242,7 @@ Qed.
Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B := Definition authC_map {A B} (f : A -n> B) : authC A -n> authC B :=
CofeMor (auth_map f). CofeMor (auth_map f).
Lemma authC_map_ne A B n : Proper (dist n ==> dist n) (@authC_map A B). Lemma authC_map_ne A B n : Proper (dist n ==> dist n) (@authC_map A B).
Proof. intros f f' Hf [[a| |] b]; repeat constructor; apply Hf. Qed. Proof. intros f f' Hf [[[a|]|] b]; repeat constructor; apply Hf. Qed.
Program Definition authURF (F : urFunctor) : urFunctor := {| Program Definition authURF (F : urFunctor) : urFunctor := {|
urFunctor_car A B := authUR (urFunctor_car F A B); urFunctor_car A B := authUR (urFunctor_car F A B);
......
This diff is collapsed.
...@@ -88,6 +88,8 @@ Section cofe_mixin. ...@@ -88,6 +88,8 @@ Section cofe_mixin.
Proof. apply (mixin_conv_compl _ (cofe_mixin A)). Qed. Proof. apply (mixin_conv_compl _ (cofe_mixin A)). Qed.
End cofe_mixin. End cofe_mixin.
Hint Extern 1 (_ {_} _) => apply equiv_dist; assumption.
(** Discrete COFEs and Timeless elements *) (** Discrete COFEs and Timeless elements *)
(* TODO: On paper, We called these "discrete elements". I think that makes (* TODO: On paper, We called these "discrete elements". I think that makes
more sense. *) more sense. *)
...@@ -151,8 +153,7 @@ Section cofe. ...@@ -151,8 +153,7 @@ Section cofe.
Qed. Qed.
Lemma timeless_iff n (x : A) `{!Timeless x} y : x y x {n} y. Lemma timeless_iff n (x : A) `{!Timeless x} y : x y x {n} y.
Proof. Proof.
split; intros; [by apply equiv_dist|]. split; intros; auto. apply (timeless _), dist_le with n; auto with lia.
apply (timeless _), dist_le with n; auto with lia.
Qed. Qed.
End cofe. End cofe.
...@@ -569,6 +570,9 @@ Section option. ...@@ -569,6 +570,9 @@ Section option.
Proof. destruct 1; split; eauto. Qed. Proof. destruct 1; split; eauto. Qed.
Global Instance Some_dist_inj : Inj (dist n) (dist n) (@Some A). Global Instance Some_dist_inj : Inj (dist n) (dist n) (@Some A).
Proof. by inversion_clear 1. Qed. Proof. by inversion_clear 1. Qed.
Global Instance from_option_ne {B} (R : relation B) (f : A B) n :
Proper (dist n ==> R) f Proper (R ==> dist n ==> R) (from_option f).
Proof. destruct 3; simpl; auto. Qed.
Global Instance None_timeless : Timeless (@None A). Global Instance None_timeless : Timeless (@None A).
Proof. inversion_clear 1; constructor. Qed. Proof. inversion_clear 1; constructor. Qed.
...@@ -592,14 +596,9 @@ End option. ...@@ -592,14 +596,9 @@ End option.
Typeclasses Opaque option_dist. Typeclasses Opaque option_dist.
Arguments optionC : clear implicits. Arguments optionC : clear implicits.
Instance from_option_ne {A B : cofeT} (f : A B) n : Instance option_fmap_ne {A B : cofeT} n:
Proper (dist n ==> dist n) f Proper ((dist n ==> dist n) ==> dist n ==> dist n) (@fmap option _ A B).
Proper (dist n ==> dist n ==> dist n) (from_option f). Proof. intros f f' Hf ?? []; constructor; auto. Qed.
Proof. destruct 3; simpl; auto. Qed.
Instance option_fmap_ne {A B : cofeT} (f : A B) n:
Proper (dist n ==> dist n) f Proper (dist n==>dist n) (fmap (M:=option) f).
Proof. by intros Hf; destruct 1; constructor; apply Hf. Qed.
Definition optionC_map {A B} (f : A -n> B) : optionC A -n> optionC B := Definition optionC_map {A B} (f : A -n> B) : optionC A -n> optionC B :=
CofeMor (fmap f : optionC A optionC B). CofeMor (fmap f : optionC A optionC B).
Instance optionC_map_ne A B n : Proper (dist n ==> dist n) (@optionC_map A B). Instance optionC_map_ne A B n : Proper (dist n ==> dist n) (@optionC_map A B).
......
...@@ -2,7 +2,7 @@ From iris.algebra Require Export cmra. ...@@ -2,7 +2,7 @@ From iris.algebra Require Export cmra.
Local Arguments validN _ _ _ !_ /. Local Arguments validN _ _ _ !_ /.
Local Arguments valid _ _ !_ /. Local Arguments valid _ _ !_ /.
Local Arguments op _ _ _ !_ /. Local Arguments op _ _ _ !_ /.
Local Arguments core _ _ !_ /. Local Arguments pcore _ _ !_ /.
(* This is isomorphic to option, but has a very different RA structure. *) (* This is isomorphic to option, but has a very different RA structure. *)
Inductive dec_agree (A : Type) : Type := Inductive dec_agree (A : Type) : Type :=
...@@ -26,19 +26,19 @@ Instance dec_agree_op : Op (dec_agree A) := λ x y, ...@@ -26,19 +26,19 @@ Instance dec_agree_op : Op (dec_agree A) := λ x y,
| DecAgree a, DecAgree b => if decide (a = b) then DecAgree a else DecAgreeBot | DecAgree a, DecAgree b => if decide (a = b) then DecAgree a else DecAgreeBot
| _, _ => DecAgreeBot | _, _ => DecAgreeBot
end. end.
Instance dec_agree_core : Core (dec_agree A) := id. Instance dec_agree_pcore : PCore (dec_agree A) := Some.
Definition dec_agree_ra_mixin : RAMixin (dec_agree A). Definition dec_agree_ra_mixin : RAMixin (dec_agree A).
Proof. Proof.
split. split.
- apply _. - apply _.
- apply _. - intros x y cx ? [=<-]; eauto.
- apply _. - apply _.
- intros [?|] [?|] [?|]; by repeat (simplify_eq/= || case_match). - intros [?|] [?|] [?|]; by repeat (simplify_eq/= || case_match).
- intros [?|] [?|]; by repeat (simplify_eq/= || case_match). - intros [?|] [?|]; by repeat (simplify_eq/= || case_match).
- intros [?|] ? [=<-]; by repeat (simplify_eq/= || case_match).
- intros [?|]; by repeat (simplify_eq/= || case_match). - intros [?|]; by repeat (simplify_eq/= || case_match).
- intros [?|]; by repeat (simplify_eq/= || case_match). - intros [?|] [?|] ?? [=<-]; eauto.
- by intros [?|] [?|] ?.
- by intros [?|] [?|] ?. - by intros [?|] [?|] ?.
Qed. Qed.
...@@ -47,7 +47,7 @@ Canonical Structure dec_agreeR : cmraT := ...@@ -47,7 +47,7 @@ Canonical Structure dec_agreeR : cmraT :=
(* Some properties of this CMRA *) (* Some properties of this CMRA *)
Global Instance dec_agree_persistent (x : dec_agreeR) : Persistent x. Global Instance dec_agree_persistent (x : dec_agreeR) : Persistent x.
Proof. done. Qed. Proof. by constructor. Qed.
Lemma dec_agree_ne a b : a b DecAgree a DecAgree b = DecAgreeBot. Lemma dec_agree_ne a b : a b DecAgree a DecAgree b = DecAgreeBot.
Proof. intros. by rewrite /= decide_False. Qed. Proof. intros. by rewrite /= decide_False. Qed.
......
...@@ -142,8 +142,8 @@ Hint Immediate dra_disjoint_move_l dra_disjoint_move_r. ...@@ -142,8 +142,8 @@ Hint Immediate dra_disjoint_move_l dra_disjoint_move_r.
Lemma validity_valid_car_valid z : z validity_car z. Lemma validity_valid_car_valid z : z validity_car z.
Proof. apply validity_prf. Qed. Proof. apply validity_prf. Qed.
Hint Resolve validity_valid_car_valid. Hint Resolve validity_valid_car_valid.
Program Instance validity_core : Core (validity A) := λ x, Program Instance validity_pcore : PCore (validity A) := λ x,
Validity (core (validity_car x)) ( x) _. Some (Validity (core (validity_car x)) ( x) _).
Solve Obligations with naive_solver eauto using dra_core_valid. Solve Obligations with naive_solver eauto using dra_core_valid.
Program Instance validity_op : Op (validity A) := λ x y, Program Instance validity_op : Op (validity A) := λ x y,
Validity (validity_car x validity_car y) Validity (validity_car x validity_car y)
...@@ -152,7 +152,7 @@ Solve Obligations with naive_solver eauto using dra_op_valid. ...@@ -152,7 +152,7 @@ Solve Obligations with naive_solver eauto using dra_op_valid.
Definition validity_ra_mixin : RAMixin (validity A). Definition validity_ra_mixin : RAMixin (validity A).
Proof. Proof.
split. apply ra_total_mixin; first eauto.
- intros ??? [? Heq]; split; simpl; [|by intros (?&?&?); rewrite Heq]. - intros ??? [? Heq]; split; simpl; [|by intros (?&?&?); rewrite Heq].
split; intros (?&?&?); split_and!; split; intros (?&?&?); split_and!;
first [rewrite ?Heq; tauto|rewrite -?Heq; tauto|tauto]. first [rewrite ?Heq; tauto|rewrite -?Heq; tauto|tauto].
...@@ -176,6 +176,9 @@ Qed. ...@@ -176,6 +176,9 @@ Qed.
Canonical Structure validityR : cmraT := Canonical Structure validityR : cmraT :=
discreteR (validity A) validity_ra_mixin. discreteR (validity A) validity_ra_mixin.
Global Instance validity_cmra_total : CMRATotal validityR.
Proof. rewrite /CMRATotal; eauto. Qed.
Lemma validity_update x y : Lemma validity_update x y :
( c, x c validity_car x c y validity_car y c) x ~~> y. ( c, x c validity_car x c y validity_car y c) x ~~> y.
Proof. Proof.
......
...@@ -5,11 +5,13 @@ Local Arguments valid _ _ !_ /. ...@@ -5,11 +5,13 @@ Local Arguments valid _ _ !_ /.
Inductive excl (A : Type) := Inductive excl (A : Type) :=
| Excl : A excl A | Excl : A excl A
| ExclUnit : excl A
| ExclBot : excl A. | ExclBot : excl A.
Arguments Excl {_} _. Arguments Excl {_} _.
Arguments ExclUnit {_}.
Arguments ExclBot {_}. Arguments ExclBot {_}.
Notation Excl' x := (Some (Excl x)).
Notation ExclBot' := (Some ExclBot).
Instance maybe_Excl {A} : Maybe (@Excl A) := λ x, Instance maybe_Excl {A} : Maybe (@Excl A) := λ x,
match x with Excl a => Some a | _ => None end. match x with Excl a => Some a | _ => None end.
...@@ -21,12 +23,10 @@ Implicit Types x y : excl A. ...@@ -21,12 +23,10 @@ Implicit Types x y : excl A.
(* Cofe *) (* Cofe *)
Inductive excl_equiv : Equiv (excl A) := Inductive excl_equiv : Equiv (excl A) :=
| Excl_equiv a b : a b Excl a Excl b | Excl_equiv a b : a b Excl a Excl b
| ExclUnit_equiv : ExclUnit ExclUnit
| ExclBot_equiv : ExclBot ExclBot. | ExclBot_equiv : ExclBot ExclBot.
Existing Instance excl_equiv. Existing Instance excl_equiv.
Inductive excl_dist : Dist (excl A) := Inductive excl_dist : Dist (excl A) :=
| Excl_dist a b n : a {n} b Excl a {n} Excl b | Excl_dist a b n : a {n} b Excl a {n} Excl b
| ExclUnit_dist n : ExclUnit {n} ExclUnit
| ExclBot_dist n : ExclBot {n} ExclBot. | ExclBot_dist n : ExclBot {n} ExclBot.
Existing Instance excl_dist. Existing Instance excl_dist.
...@@ -67,43 +67,31 @@ Proof. by destruct 2; f_equal; apply leibniz_equiv. Qed. ...@@ -67,43 +67,31 @@ Proof. by destruct 2; f_equal; apply leibniz_equiv. Qed.
Global Instance Excl_timeless a : Timeless a Timeless (Excl a). Global Instance Excl_timeless a : Timeless a Timeless (Excl a).
Proof. by inversion_clear 2; constructor; apply (timeless _). Qed. Proof. by inversion_clear 2; constructor; apply (timeless _). Qed.
Global Instance ExclUnit_timeless : Timeless (@ExclUnit A).
Proof. by inversion_clear 1; constructor. Qed.
Global Instance ExclBot_timeless : Timeless (@ExclBot A). Global Instance ExclBot_timeless : Timeless (@ExclBot A).
Proof. by inversion_clear 1; constructor. Qed. Proof. by inversion_clear 1; constructor. Qed.
(* CMRA *) (* CMRA *)
Instance excl_valid : Valid (excl A) := λ