Commit f372c5c1 authored by Robbert Krebbers's avatar Robbert Krebbers

Rename algebra/fin_maps.v -> algebra/gmap.v

Also remove some superfluous map_ prefixes.
parent 9fd42107
...@@ -41,7 +41,7 @@ algebra/cmra_big_op.v ...@@ -41,7 +41,7 @@ algebra/cmra_big_op.v
algebra/cmra_tactics.v algebra/cmra_tactics.v
algebra/sts.v algebra/sts.v
algebra/auth.v algebra/auth.v
algebra/fin_maps.v algebra/gmap.v
algebra/cofe.v algebra/cofe.v
algebra/base.v algebra/base.v
algebra/dra.v algebra/dra.v
......
...@@ -6,14 +6,14 @@ Section cofe. ...@@ -6,14 +6,14 @@ Section cofe.
Context `{Countable K} {A : cofeT}. Context `{Countable K} {A : cofeT}.
Implicit Types m : gmap K A. Implicit Types m : gmap K A.
Instance map_dist : Dist (gmap K A) := λ n m1 m2, Instance gmap_dist : Dist (gmap K A) := λ n m1 m2,
i, m1 !! i {n} m2 !! i. i, m1 !! i {n} m2 !! i.
Program Definition map_chain (c : chain (gmap K A)) Program Definition gmap_chain (c : chain (gmap K A))
(k : K) : chain (option A) := {| chain_car n := c n !! k |}. (k : K) : chain (option A) := {| chain_car n := c n !! k |}.
Next Obligation. by intros c k n i ?; apply (chain_cauchy c). Qed. Next Obligation. by intros c k n i ?; apply (chain_cauchy c). Qed.
Instance map_compl : Compl (gmap K A) := λ c, Instance gmap_compl : Compl (gmap K A) := λ c,
map_imap (λ i _, compl (map_chain c i)) (c 0). map_imap (λ i _, compl (gmap_chain c i)) (c 0).
Definition map_cofe_mixin : CofeMixin (gmap K A). Definition gmap_cofe_mixin : CofeMixin (gmap K A).
Proof. Proof.
split. split.
- intros m1 m2; split. - intros m1 m2; split.
...@@ -24,15 +24,15 @@ Proof. ...@@ -24,15 +24,15 @@ Proof.
+ by intros m1 m2 ? k. + by intros m1 m2 ? k.
+ by intros m1 m2 m3 ?? k; trans (m2 !! k). + by intros m1 m2 m3 ?? k; trans (m2 !! k).
- by intros n m1 m2 ? k; apply dist_S. - by intros n m1 m2 ? k; apply dist_S.
- intros n c k; rewrite /compl /map_compl lookup_imap. - intros n c k; rewrite /compl /gmap_compl lookup_imap.
feed inversion (λ H, chain_cauchy c 0 n H k); simpl; auto with lia. feed inversion (λ H, chain_cauchy c 0 n H k); simpl; auto with lia.
by rewrite conv_compl /=; apply reflexive_eq. by rewrite conv_compl /=; apply reflexive_eq.
Qed. Qed.
Canonical Structure mapC : cofeT := CofeT map_cofe_mixin. Canonical Structure gmapC : cofeT := CofeT gmap_cofe_mixin.
Global Instance map_discrete : Discrete A Discrete mapC. Global Instance gmap_discrete : Discrete A Discrete gmapC.
Proof. intros ? m m' ? i. by apply (timeless _). Qed. Proof. intros ? m m' ? i. by apply (timeless _). Qed.
(* why doesn't this go automatic? *) (* why doesn't this go automatic? *)
Global Instance mapC_leibniz: LeibnizEquiv A LeibnizEquiv mapC. Global Instance gmapC_leibniz: LeibnizEquiv A LeibnizEquiv gmapC.
Proof. intros; change (LeibnizEquiv (gmap K A)); apply _. Qed. Proof. intros; change (LeibnizEquiv (gmap K A)); apply _. Qed.
Global Instance lookup_ne n k : Global Instance lookup_ne n k :
...@@ -62,47 +62,47 @@ Proof. ...@@ -62,47 +62,47 @@ Proof.
[by constructor|by apply lookup_ne]. [by constructor|by apply lookup_ne].
Qed. Qed.
Instance map_empty_timeless : Timeless ( : gmap K A). Instance gmap_empty_timeless : Timeless ( : gmap K A).
Proof. Proof.
intros m Hm i; specialize (Hm i); rewrite lookup_empty in Hm |- *. intros m Hm i; specialize (Hm i); rewrite lookup_empty in Hm |- *.
inversion_clear Hm; constructor. inversion_clear Hm; constructor.
Qed. Qed.
Global Instance map_lookup_timeless m i : Timeless m Timeless (m !! i). Global Instance gmap_lookup_timeless m i : Timeless m Timeless (m !! i).
Proof. Proof.
intros ? [x|] Hx; [|by symmetry; apply: timeless]. intros ? [x|] Hx; [|by symmetry; apply: timeless].
assert (m {0} <[i:=x]> m) assert (m {0} <[i:=x]> m)
by (by symmetry in Hx; inversion Hx; cofe_subst; rewrite insert_id). by (by symmetry in Hx; inversion Hx; cofe_subst; rewrite insert_id).
by rewrite (timeless m (<[i:=x]>m)) // lookup_insert. by rewrite (timeless m (<[i:=x]>m)) // lookup_insert.
Qed. Qed.
Global Instance map_insert_timeless m i x : Global Instance gmap_insert_timeless m i x :
Timeless x Timeless m Timeless (<[i:=x]>m). Timeless x Timeless m Timeless (<[i:=x]>m).
Proof. Proof.
intros ?? m' Hm j; destruct (decide (i = j)); simplify_map_eq. intros ?? m' Hm j; destruct (decide (i = j)); simplify_map_eq.
{ by apply: timeless; rewrite -Hm lookup_insert. } { by apply: timeless; rewrite -Hm lookup_insert. }
by apply: timeless; rewrite -Hm lookup_insert_ne. by apply: timeless; rewrite -Hm lookup_insert_ne.
Qed. Qed.
Global Instance map_singleton_timeless i x : Global Instance gmap_singleton_timeless i x :
Timeless x Timeless ({[ i := x ]} : gmap K A) := _. Timeless x Timeless ({[ i := x ]} : gmap K A) := _.
End cofe. End cofe.
Arguments mapC _ {_ _} _. Arguments gmapC _ {_ _} _.
(* CMRA *) (* CMRA *)
Section cmra. Section cmra.
Context `{Countable K} {A : cmraT}. Context `{Countable K} {A : cmraT}.
Implicit Types m : gmap K A. Implicit Types m : gmap K A.
Instance map_op : Op (gmap K A) := merge op. Instance gmap_op : Op (gmap K A) := merge op.
Instance map_core : Core (gmap K A) := fmap core. Instance gmap_core : Core (gmap K A) := fmap core.
Instance map_valid : Valid (gmap K A) := λ m, i, (m !! i). Instance gmap_valid : Valid (gmap K A) := λ m, i, (m !! i).
Instance map_validN : ValidN (gmap K A) := λ n m, i, {n} (m !! i). Instance gmap_validN : ValidN (gmap K A) := λ n m, i, {n} (m !! i).
Lemma lookup_op m1 m2 i : (m1 m2) !! i = m1 !! i m2 !! i. Lemma lookup_op m1 m2 i : (m1 m2) !! i = m1 !! i m2 !! i.
Proof. by apply lookup_merge. Qed. Proof. by apply lookup_merge. Qed.
Lemma lookup_core m i : core m !! i = core (m !! i). Lemma lookup_core m i : core m !! i = core (m !! i).
Proof. by apply lookup_fmap. Qed. Proof. by apply lookup_fmap. Qed.
Lemma map_included_spec (m1 m2 : gmap K A) : m1 m2 i, m1 !! i m2 !! i. Lemma gmap_included_spec (m1 m2 : gmap K A) : m1 m2 i, m1 !! i m2 !! i.
Proof. Proof.
split; [by intros [m Hm] i; exists (m !! i); rewrite -lookup_op Hm|]. split; [by intros [m Hm] i; exists (m !! i); rewrite -lookup_op Hm|].
revert m2. induction m1 as [|i x m Hi IH] using map_ind=> m2 Hm. revert m2. induction m1 as [|i x m Hi IH] using map_ind=> m2 Hm.
...@@ -118,7 +118,7 @@ Proof. ...@@ -118,7 +118,7 @@ Proof.
lookup_insert_ne // lookup_partial_alter_ne. lookup_insert_ne // lookup_partial_alter_ne.
Qed. Qed.
Definition map_cmra_mixin : CMRAMixin (gmap K A). Definition gmap_cmra_mixin : CMRAMixin (gmap K A).
Proof. Proof.
split. split.
- by intros n m1 m2 m3 Hm i; rewrite !lookup_op (Hm i). - by intros n m1 m2 m3 Hm i; rewrite !lookup_op (Hm i).
...@@ -132,7 +132,7 @@ Proof. ...@@ -132,7 +132,7 @@ Proof.
- by intros m1 m2 i; rewrite !lookup_op comm. - by intros m1 m2 i; rewrite !lookup_op comm.
- by intros m i; rewrite lookup_op !lookup_core cmra_core_l. - by intros m i; rewrite lookup_op !lookup_core cmra_core_l.
- by intros m i; rewrite !lookup_core cmra_core_idemp. - by intros m i; rewrite !lookup_core cmra_core_idemp.
- intros x y; rewrite !map_included_spec; intros Hm i. - intros x y; rewrite !gmap_included_spec; intros Hm i.
by rewrite !lookup_core; apply cmra_core_preserving. by rewrite !lookup_core; apply cmra_core_preserving.
- intros n m1 m2 Hm i; apply cmra_validN_op_l with (m2 !! i). - intros n m1 m2 Hm i; apply cmra_validN_op_l with (m2 !! i).
by rewrite -lookup_op. by rewrite -lookup_op.
...@@ -152,25 +152,25 @@ Proof. ...@@ -152,25 +152,25 @@ Proof.
pose proof (Hm12' i) as Hm12''; rewrite Hx in Hm12''. pose proof (Hm12' i) as Hm12''; rewrite Hx in Hm12''.
by symmetry; apply option_op_positive_dist_r with (m1 !! i). by symmetry; apply option_op_positive_dist_r with (m1 !! i).
Qed. Qed.
Canonical Structure mapR : cmraT := CMRAT map_cofe_mixin map_cmra_mixin. Canonical Structure gmapR : cmraT := CMRAT gmap_cofe_mixin gmap_cmra_mixin.
Global Instance map_cmra_unit : CMRAUnit mapR. Global Instance gmap_cmra_unit : CMRAUnit gmapR.
Proof. Proof.
split. split.
- by intros i; rewrite lookup_empty. - by intros i; rewrite lookup_empty.
- by intros m i; rewrite /= lookup_op lookup_empty (left_id_L None _). - by intros m i; rewrite /= lookup_op lookup_empty (left_id_L None _).
- apply map_empty_timeless. - apply gmap_empty_timeless.
Qed. Qed.
Global Instance map_cmra_discrete : CMRADiscrete A CMRADiscrete mapR. Global Instance gmap_cmra_discrete : CMRADiscrete A CMRADiscrete gmapR.
Proof. split; [apply _|]. intros m ? i. by apply: cmra_discrete_valid. Qed. Proof. split; [apply _|]. intros m ? i. by apply: cmra_discrete_valid. Qed.
(** Internalized properties *) (** Internalized properties *)
Lemma map_equivI {M} m1 m2 : (m1 m2) ⊣⊢ ( i, m1 !! i m2 !! i : uPred M). Lemma gmap_equivI {M} m1 m2 : (m1 m2) ⊣⊢ ( i, m1 !! i m2 !! i : uPred M).
Proof. by uPred.unseal. Qed. Proof. by uPred.unseal. Qed.
Lemma map_validI {M} m : ( m) ⊣⊢ ( i, (m !! i) : uPred M). Lemma gmap_validI {M} m : ( m) ⊣⊢ ( i, (m !! i) : uPred M).
Proof. by uPred.unseal. Qed. Proof. by uPred.unseal. Qed.
End cmra. End cmra.
Arguments mapR _ {_ _} _. Arguments gmapR _ {_ _} _.
Section properties. Section properties.
Context `{Countable K} {A : cmraT}. Context `{Countable K} {A : cmraT}.
...@@ -178,23 +178,23 @@ Implicit Types m : gmap K A. ...@@ -178,23 +178,23 @@ Implicit Types m : gmap K A.
Implicit Types i : K. Implicit Types i : K.
Implicit Types a : A. Implicit Types a : A.
Lemma map_lookup_validN n m i x : {n} m m !! i {n} Some x {n} x. Lemma lookup_validN n m i x : {n} m m !! i {n} Some x {n} x.
Proof. by move=> /(_ i) Hm Hi; move:Hm; rewrite Hi. Qed. Proof. by move=> /(_ i) Hm Hi; move:Hm; rewrite Hi. Qed.
Lemma map_lookup_valid m i x : m m !! i Some x x. Lemma lookup_valid m i x : m m !! i Some x x.
Proof. move=> Hm Hi. move:(Hm i). by rewrite Hi. Qed. Proof. move=> Hm Hi. move:(Hm i). by rewrite Hi. Qed.
Lemma map_insert_validN n m i x : {n} x {n} m {n} <[i:=x]>m. Lemma insert_validN n m i x : {n} x {n} m {n} <[i:=x]>m.
Proof. by intros ?? j; destruct (decide (i = j)); simplify_map_eq. Qed. Proof. by intros ?? j; destruct (decide (i = j)); simplify_map_eq. Qed.
Lemma map_insert_valid m i x : x m <[i:=x]>m. Lemma insert_valid m i x : x m <[i:=x]>m.
Proof. by intros ?? j; destruct (decide (i = j)); simplify_map_eq. Qed. Proof. by intros ?? j; destruct (decide (i = j)); simplify_map_eq. Qed.
Lemma map_singleton_validN n i x : {n} ({[ i := x ]} : gmap K A) {n} x. Lemma singleton_validN n i x : {n} ({[ i := x ]} : gmap K A) {n} x.
Proof. Proof.
split; [|by intros; apply map_insert_validN, cmra_unit_validN]. split; [|by intros; apply insert_validN, cmra_unit_validN].
by move=>/(_ i); simplify_map_eq. by move=>/(_ i); simplify_map_eq.
Qed. Qed.
Lemma map_singleton_valid i x : ({[ i := x ]} : gmap K A) x. Lemma singleton_valid i x : ({[ i := x ]} : gmap K A) x.
Proof. rewrite !cmra_valid_validN. by setoid_rewrite map_singleton_validN. Qed. Proof. rewrite !cmra_valid_validN. by setoid_rewrite singleton_validN. Qed.
Lemma map_insert_singleton_opN n m i x : Lemma insert_singleton_opN n m i x :
m !! i = None m !! i {n} Some (core x) <[i:=x]> m {n} {[ i := x ]} m. m !! i = None m !! i {n} Some (core x) <[i:=x]> m {n} {[ i := x ]} m.
Proof. Proof.
intros Hi j; destruct (decide (i = j)) as [->|]; intros Hi j; destruct (decide (i = j)) as [->|];
...@@ -202,24 +202,22 @@ Proof. ...@@ -202,24 +202,22 @@ Proof.
rewrite lookup_op lookup_insert lookup_singleton. rewrite lookup_op lookup_insert lookup_singleton.
by destruct Hi as [->| ->]; constructor; rewrite ?cmra_core_r. by destruct Hi as [->| ->]; constructor; rewrite ?cmra_core_r.
Qed. Qed.
Lemma map_insert_singleton_op m i x : Lemma insert_singleton_op m i x :
m !! i = None m !! i Some (core x) <[i:=x]> m {[ i := x ]} m. m !! i = None m !! i Some (core x) <[i:=x]> m {[ i := x ]} m.
Proof. Proof. rewrite !equiv_dist; naive_solver eauto using insert_singleton_opN. Qed.
rewrite !equiv_dist; naive_solver eauto using map_insert_singleton_opN.
Qed.
Lemma map_core_singleton (i : K) (x : A) : Lemma core_singleton (i : K) (x : A) :
core ({[ i := x ]} : gmap K A) = {[ i := core x ]}. core ({[ i := x ]} : gmap K A) = {[ i := core x ]}.
Proof. apply map_fmap_singleton. Qed. Proof. apply map_fmap_singleton. Qed.
Lemma map_op_singleton (i : K) (x y : A) : Lemma op_singleton (i : K) (x y : A) :
{[ i := x ]} {[ i := y ]} = ({[ i := x y ]} : gmap K A). {[ i := x ]} {[ i := y ]} = ({[ i := x y ]} : gmap K A).
Proof. by apply (merge_singleton _ _ _ x y). Qed. Proof. by apply (merge_singleton _ _ _ x y). Qed.
Global Instance map_persistent m : ( x : A, Persistent x) Persistent m. Global Instance gmap_persistent m : ( x : A, Persistent x) Persistent m.
Proof. intros ? i. by rewrite lookup_core persistent. Qed. Proof. intros ? i. by rewrite lookup_core persistent. Qed.
Global Instance map_singleton_persistent i (x : A) : Global Instance gmap_singleton_persistent i (x : A) :
Persistent x Persistent {[ i := x ]}. Persistent x Persistent {[ i := x ]}.
Proof. intros. by rewrite /Persistent map_core_singleton persistent. Qed. Proof. intros. by rewrite /Persistent core_singleton persistent. Qed.
Lemma singleton_includedN n m i x : Lemma singleton_includedN n m i x :
{[ i := x ]} {n} m y, m !! i {n} Some y x {n} y. {[ i := x ]} {n} m y, m !! i {n} Some y x {n} y.
...@@ -234,14 +232,14 @@ Proof. ...@@ -234,14 +232,14 @@ Proof.
+ rewrite Hi lookup_op lookup_singleton lookup_insert. by constructor. + rewrite Hi lookup_op lookup_singleton lookup_insert. by constructor.
+ by rewrite lookup_op lookup_singleton_ne // lookup_insert_ne // left_id. + by rewrite lookup_op lookup_singleton_ne // lookup_insert_ne // left_id.
Qed. Qed.
Lemma map_dom_op m1 m2 : dom (gset K) (m1 m2) dom _ m1 dom _ m2. Lemma dom_op m1 m2 : dom (gset K) (m1 m2) dom _ m1 dom _ m2.
Proof. Proof.
apply elem_of_equiv; intros i; rewrite elem_of_union !elem_of_dom. apply elem_of_equiv; intros i; rewrite elem_of_union !elem_of_dom.
unfold is_Some; setoid_rewrite lookup_op. unfold is_Some; setoid_rewrite lookup_op.
destruct (m1 !! i), (m2 !! i); naive_solver. destruct (m1 !! i), (m2 !! i); naive_solver.
Qed. Qed.
Lemma map_insert_updateP (P : A Prop) (Q : gmap K A Prop) m i x : Lemma insert_updateP (P : A Prop) (Q : gmap K A Prop) m i x :
x ~~>: P ( y, P y Q (<[i:=y]>m)) <[i:=x]>m ~~>: Q. x ~~>: P ( y, P y Q (<[i:=y]>m)) <[i:=x]>m ~~>: Q.
Proof. Proof.
intros Hx%option_updateP' HP n mf Hm. intros Hx%option_updateP' HP n mf Hm.
...@@ -251,24 +249,22 @@ Proof. ...@@ -251,24 +249,22 @@ Proof.
intros j; move: (Hm j)=>{Hm}; rewrite !lookup_op=>Hm. intros j; move: (Hm j)=>{Hm}; rewrite !lookup_op=>Hm.
destruct (decide (i = j)); simplify_map_eq/=; auto. destruct (decide (i = j)); simplify_map_eq/=; auto.
Qed. Qed.
Lemma map_insert_updateP' (P : A Prop) m i x : Lemma insert_updateP' (P : A Prop) m i x :
x ~~>: P <[i:=x]>m ~~>: λ m', y, m' = <[i:=y]>m P y. x ~~>: P <[i:=x]>m ~~>: λ m', y, m' = <[i:=y]>m P y.
Proof. eauto using map_insert_updateP. Qed. Proof. eauto using insert_updateP. Qed.
Lemma map_insert_update m i x y : x ~~> y <[i:=x]>m ~~> <[i:=y]>m. Lemma insert_update m i x y : x ~~> y <[i:=x]>m ~~> <[i:=y]>m.
Proof. Proof. rewrite !cmra_update_updateP; eauto using insert_updateP with subst. Qed.
rewrite !cmra_update_updateP; eauto using map_insert_updateP with subst.
Qed.
Lemma map_singleton_updateP (P : A Prop) (Q : gmap K A Prop) i x : Lemma singleton_updateP (P : A Prop) (Q : gmap K A Prop) i x :
x ~~>: P ( y, P y Q {[ i := y ]}) {[ i := x ]} ~~>: Q. x ~~>: P ( y, P y Q {[ i := y ]}) {[ i := x ]} ~~>: Q.
Proof. apply map_insert_updateP. Qed. Proof. apply insert_updateP. Qed.
Lemma map_singleton_updateP' (P : A Prop) i x : Lemma singleton_updateP' (P : A Prop) i x :
x ~~>: P {[ i := x ]} ~~>: λ m, y, m = {[ i := y ]} P y. x ~~>: P {[ i := x ]} ~~>: λ m, y, m = {[ i := y ]} P y.
Proof. apply map_insert_updateP'. Qed. Proof. apply insert_updateP'. Qed.
Lemma map_singleton_update i (x y : A) : x ~~> y {[ i := x ]} ~~> {[ i := y ]}. Lemma singleton_update i (x y : A) : x ~~> y {[ i := x ]} ~~> {[ i := y ]}.
Proof. apply map_insert_update. Qed. Proof. apply insert_update. Qed.
Lemma map_singleton_updateP_empty `{Empty A, !CMRAUnit A} Lemma singleton_updateP_empty `{Empty A, !CMRAUnit A}
(P : A Prop) (Q : gmap K A Prop) i : (P : A Prop) (Q : gmap K A Prop) i :
~~>: P ( y, P y Q {[ i := y ]}) ~~>: Q. ~~>: P ( y, P y Q {[ i := y ]}) ~~>: Q.
Proof. Proof.
...@@ -283,34 +279,34 @@ Proof. ...@@ -283,34 +279,34 @@ Proof.
by rewrite right_id. by rewrite right_id.
- move:(Hg i'). by rewrite !lookup_op lookup_singleton_ne // !left_id. - move:(Hg i'). by rewrite !lookup_op lookup_singleton_ne // !left_id.
Qed. Qed.
Lemma map_singleton_updateP_empty' `{Empty A, !CMRAUnit A} (P: A Prop) i : Lemma singleton_updateP_empty' `{Empty A, !CMRAUnit A} (P: A Prop) i :
~~>: P ~~>: λ m, y, m = {[ i := y ]} P y. ~~>: P ~~>: λ m, y, m = {[ i := y ]} P y.
Proof. eauto using map_singleton_updateP_empty. Qed. Proof. eauto using singleton_updateP_empty. Qed.
Section freshness. Section freshness.
Context `{Fresh K (gset K), !FreshSpec K (gset K)}. Context `{Fresh K (gset K), !FreshSpec K (gset K)}.
Lemma map_updateP_alloc_strong (Q : gmap K A Prop) (I : gset K) m x : Lemma updateP_alloc_strong (Q : gmap K A Prop) (I : gset K) m x :
x ( i, m !! i = None i I Q (<[i:=x]>m)) m ~~>: Q. x ( i, m !! i = None i I Q (<[i:=x]>m)) m ~~>: Q.
Proof. Proof.
intros ? HQ n mf Hm. set (i := fresh (I dom (gset K) (m mf))). intros ? HQ n mf Hm. set (i := fresh (I dom (gset K) (m mf))).
assert (i I i dom (gset K) m i dom (gset K) mf) as [?[??]]. assert (i I i dom (gset K) m i dom (gset K) mf) as [?[??]].
{ rewrite -not_elem_of_union -map_dom_op -not_elem_of_union; apply is_fresh. } { rewrite -not_elem_of_union -dom_op -not_elem_of_union; apply is_fresh. }
exists (<[i:=x]>m); split. exists (<[i:=x]>m); split.
{ by apply HQ; last done; apply not_elem_of_dom. } { by apply HQ; last done; apply not_elem_of_dom. }
rewrite map_insert_singleton_opN; last by left; apply not_elem_of_dom. rewrite insert_singleton_opN; last by left; apply not_elem_of_dom.
rewrite -assoc -map_insert_singleton_opN; rewrite -assoc -insert_singleton_opN;
last by left; apply not_elem_of_dom; rewrite map_dom_op not_elem_of_union. last by left; apply not_elem_of_dom; rewrite dom_op not_elem_of_union.
by apply map_insert_validN; [apply cmra_valid_validN|]. by apply insert_validN; [apply cmra_valid_validN|].
Qed. Qed.
Lemma map_updateP_alloc (Q : gmap K A Prop) m x : Lemma updateP_alloc (Q : gmap K A Prop) m x :
x ( i, m !! i = None Q (<[i:=x]>m)) m ~~>: Q. x ( i, m !! i = None Q (<[i:=x]>m)) m ~~>: Q.
Proof. move=>??. eapply map_updateP_alloc_strong with (I:=); by eauto. Qed. Proof. move=>??. eapply updateP_alloc_strong with (I:=); by eauto. Qed.
Lemma map_updateP_alloc_strong' m x (I : gset K) : Lemma updateP_alloc_strong' m x (I : gset K) :
x m ~~>: λ m', i, i I m' = <[i:=x]>m m !! i = None. x m ~~>: λ m', i, i I m' = <[i:=x]>m m !! i = None.
Proof. eauto using map_updateP_alloc_strong. Qed. Proof. eauto using updateP_alloc_strong. Qed.
Lemma map_updateP_alloc' m x : Lemma updateP_alloc' m x :
x m ~~>: λ m', i, m' = <[i:=x]>m m !! i = None. x m ~~>: λ m', i, m' = <[i:=x]>m m !! i = None.
Proof. eauto using map_updateP_alloc. Qed. Proof. eauto using updateP_alloc. Qed.
End freshness. End freshness.
(* Allocation is a local update: Just use composition with a singleton map. *) (* Allocation is a local update: Just use composition with a singleton map. *)
...@@ -319,7 +315,7 @@ End freshness. ...@@ -319,7 +315,7 @@ End freshness.
deallocation. *) deallocation. *)
(* Applying a local update at a position we own is a local update. *) (* Applying a local update at a position we own is a local update. *)
Global Instance map_alter_update `{!LocalUpdate Lv L} i : Global Instance gmap_alter_update `{!LocalUpdate Lv L} i :
LocalUpdate (λ m, x, m !! i = Some x Lv x) (alter L i). LocalUpdate (λ m, x, m !! i = Some x Lv x) (alter L i).
Proof. Proof.
split; first apply _. split; first apply _.
...@@ -332,32 +328,32 @@ Qed. ...@@ -332,32 +328,32 @@ Qed.
End properties. End properties.
(** Functor *) (** Functor *)
Instance map_fmap_ne `{Countable K} {A B : cofeT} (f : A B) n : Instance gmap_fmap_ne `{Countable K} {A B : cofeT} (f : A B) n :
Proper (dist n ==> dist n) f Proper (dist n ==>dist n) (fmap (M:=gmap K) f). Proper (dist n ==> dist n) f Proper (dist n ==>dist n) (fmap (M:=gmap K) f).
Proof. by intros ? m m' Hm k; rewrite !lookup_fmap; apply option_fmap_ne. Qed. Proof. by intros ? m m' Hm k; rewrite !lookup_fmap; apply option_fmap_ne. Qed.
Instance map_fmap_cmra_monotone `{Countable K} {A B : cmraT} (f : A B) Instance gmap_fmap_cmra_monotone `{Countable K} {A B : cmraT} (f : A B)
`{!CMRAMonotone f} : CMRAMonotone (fmap f : gmap K A gmap K B). `{!CMRAMonotone f} : CMRAMonotone (fmap f : gmap K A gmap K B).
Proof. Proof.
split; try apply _. split; try apply _.
- by intros n m ? i; rewrite lookup_fmap; apply (validN_preserving _). - by intros n m ? i; rewrite lookup_fmap; apply (validN_preserving _).
- intros m1 m2; rewrite !map_included_spec=> Hm i. - intros m1 m2; rewrite !gmap_included_spec=> Hm i.
by rewrite !lookup_fmap; apply: included_preserving. by rewrite !lookup_fmap; apply: included_preserving.
Qed. Qed.
Definition mapC_map `{Countable K} {A B} (f: A -n> B) : mapC K A -n> mapC K B := Definition gmapC_map `{Countable K} {A B} (f: A -n> B) :
CofeMor (fmap f : mapC K A mapC K B). gmapC K A -n> gmapC K B := CofeMor (fmap f : gmapC K A gmapC K B).
Instance mapC_map_ne `{Countable K} {A B} n : Instance gmapC_map_ne `{Countable K} {A B} n :
Proper (dist n ==> dist n) (@mapC_map K _ _ A B). Proper (dist n ==> dist n) (@gmapC_map K _ _ A B).
Proof. Proof.
intros f g Hf m k; rewrite /= !lookup_fmap. intros f g Hf m k; rewrite /= !lookup_fmap.
destruct (_ !! k) eqn:?; simpl; constructor; apply Hf. destruct (_ !! k) eqn:?; simpl; constructor; apply Hf.
Qed. Qed.
Program Definition mapCF K `{Countable K} (F : cFunctor) : cFunctor := {| Program Definition gmapCF K `{Countable K} (F : cFunctor) : cFunctor := {|
cFunctor_car A B := mapC K (cFunctor_car F A B); cFunctor_car A B := gmapC K (cFunctor_car F A B);
cFunctor_map A1 A2 B1 B2 fg := mapC_map (cFunctor_map F fg) cFunctor_map A1 A2 B1 B2 fg := gmapC_map (cFunctor_map F fg)
|}. |}.
Next Obligation. Next Obligation.
by intros K ?? F A1 A2 B1 B2 n f g Hfg; apply mapC_map_ne, cFunctor_ne. by intros K ?? F A1 A2 B1 B2 n f g Hfg; apply gmapC_map_ne, cFunctor_ne.
Qed. Qed.
Next Obligation. Next Obligation.
intros K ?? F A B x. rewrite /= -{2}(map_fmap_id x). intros K ?? F A B x. rewrite /= -{2}(map_fmap_id x).
...@@ -367,18 +363,18 @@ Next Obligation. ...@@ -367,18 +363,18 @@ Next Obligation.
intros K ?? F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -map_fmap_compose. intros K ?? F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -map_fmap_compose.
apply map_fmap_setoid_ext=>y ??; apply cFunctor_compose. apply map_fmap_setoid_ext=>y ??; apply cFunctor_compose.
Qed. Qed.
Instance mapCF_contractive K `{Countable K} F : Instance gmapCF_contractive K `{Countable K} F :
cFunctorContractive F cFunctorContractive (mapCF K F). cFunctorContractive F cFunctorContractive (gmapCF K F).
Proof. Proof.
by intros ? A1 A2 B1 B2 n f g Hfg; apply mapC_map_ne, cFunctor_contractive. by intros ? A1 A2 B1 B2 n f g Hfg; apply gmapC_map_ne, cFunctor_contractive.
Qed. Qed.
Program Definition mapRF K `{Countable K} (F : rFunctor) : rFunctor := {| Program Definition gmapRF K `{Countable K} (F : rFunctor) : rFunctor := {|
rFunctor_car A B := mapR K (rFunctor_car F A B); rFunctor_car A B := gmapR K (rFunctor_car F A B);
rFunctor_map A1 A2 B1 B2 fg := mapC_map (rFunctor_map F fg) rFunctor_map A1 A2 B1 B2 fg := gmapC_map (rFunctor_map F fg)
|}. |}.
Next Obligation. Next Obligation.
by intros K ?? F A1 A2 B1 B2 n f g Hfg; apply mapC_map_ne, rFunctor_ne. by intros K ?? F A1 A2 B1 B2 n f g Hfg; apply gmapC_map_ne, rFunctor_ne.
Qed. Qed.
Next Obligation. Next Obligation.
intros K ?? F A B x. rewrite /= -{2}(map_fmap_id x). intros K ?? F A B x. rewrite /= -{2}(map_fmap_id x).
...@@ -388,8 +384,8 @@ Next Obligation. ...@@ -388,8 +384,8 @@ Next Obligation.
intros K ?? F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -map_fmap_compose. intros K ?? F A1 A2 A3 B1 B2 B3 f g f' g' x. rewrite /= -map_fmap_compose.
apply map_fmap_setoid_ext=>y ??; apply rFunctor_compose. apply map_fmap_setoid_ext=>y ??; apply rFunctor_compose.
Qed. Qed.
Instance mapRF_contractive K `{Countable K} F : Instance gmapRF_contractive K `{Countable K} F :
rFunctorContractive F rFunctorContractive (mapRF K F). rFunctorContractive F rFunctorContractive (gmapRF K F).
Proof. Proof.
by intros ? A1 A2 B1 B2 n f g Hfg; apply mapC_map_ne, rFunctor_contractive.