Commit 5cfe326f authored by Ralf Jung's avatar Ralf Jung
Browse files

fix indentation and various nits

parent b0da646d
...@@ -66,11 +66,14 @@ Section ofe. ...@@ -66,11 +66,14 @@ Section ofe.
dyn_reservation_map_data_proj x {n} dyn_reservation_map_data_proj y dyn_reservation_map_data_proj x {n} dyn_reservation_map_data_proj y
dyn_reservation_map_token_proj x = dyn_reservation_map_token_proj y. dyn_reservation_map_token_proj x = dyn_reservation_map_token_proj y.
Global Instance DynReservationMap_ne : NonExpansive2 (@DynReservationMap A). Global Instance DynReservationMap_ne :
NonExpansive2 (@DynReservationMap A).
Proof. by split. Qed. Proof. by split. Qed.
Global Instance DynReservationMap_proper : Proper (() ==> (=) ==> ()) (@DynReservationMap A). Global Instance DynReservationMap_proper :
Proper (() ==> (=) ==> ()) (@DynReservationMap A).
Proof. by split. Qed. Proof. by split. Qed.
Global Instance dyn_reservation_map_data_proj_ne: NonExpansive (@dyn_reservation_map_data_proj A). Global Instance dyn_reservation_map_data_proj_ne :
NonExpansive (@dyn_reservation_map_data_proj A).
Proof. by destruct 1. Qed. Proof. by destruct 1. Qed.
Global Instance dyn_reservation_map_data_proj_proper : Global Instance dyn_reservation_map_data_proj_proper :
Proper (() ==> ()) (@dyn_reservation_map_data_proj A). Proper (() ==> ()) (@dyn_reservation_map_data_proj A).
...@@ -151,198 +154,195 @@ Section cmra. ...@@ -151,198 +154,195 @@ Section cmra.
| CoPsetBot => False | CoPsetBot => False
end := eq_refl _. end := eq_refl _.
Lemma dyn_reservation_map_included x y : Lemma dyn_reservation_map_included x y :
x y x y
dyn_reservation_map_data_proj x dyn_reservation_map_data_proj y dyn_reservation_map_data_proj x dyn_reservation_map_data_proj y
dyn_reservation_map_token_proj x dyn_reservation_map_token_proj y. dyn_reservation_map_token_proj x dyn_reservation_map_token_proj y.
Proof. 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 (DynReservationMap z1 z2); split; auto. intros [[z1 Hz1] [z2 Hz2]]; exists (DynReservationMap z1 z2); split; auto.
Qed. Qed.
Lemma dyn_reservation_map_data_proj_validN n x : {n} x {n} dyn_reservation_map_data_proj x. Lemma dyn_reservation_map_data_proj_validN n x : {n} x {n} dyn_reservation_map_data_proj x.
Proof. by destruct x as [? [?|]]=> // -[??]. Qed. Proof. by destruct x as [? [?|]]=> // -[??]. Qed.
Lemma dyn_reservation_map_token_proj_validN n x : {n} x {n} dyn_reservation_map_token_proj x. Lemma dyn_reservation_map_token_proj_validN n x : {n} x {n} dyn_reservation_map_token_proj x.
Proof. by destruct x as [? [?|]]=> // -[??]. Qed. Proof. by destruct x as [? [?|]]=> // -[??]. Qed.
Lemma dyn_reservation_map_cmra_mixin : CmraMixin (dyn_reservation_map A). Lemma dyn_reservation_map_cmra_mixin : CmraMixin (dyn_reservation_map A).
Proof. Proof.
apply (iso_cmra_mixin_restrict from_reservation_map to_reservation_map); try done. apply (iso_cmra_mixin_restrict from_reservation_map to_reservation_map); try done.
- intros n [m [E|]]; - intros n [m [E|]];
rewrite dyn_reservation_map_validN_eq reservation_map_validN_eq /=; rewrite dyn_reservation_map_validN_eq reservation_map_validN_eq /=;
naive_solver. naive_solver.
- intros n [m1 [E1|]] [m2 [E2|]] [Hm ?]=> // -[?[??]]; split; simplify_eq/=. - intros n [m1 [E1|]] [m2 [E2|]] [Hm ?]=> // -[?[??]]; split; simplify_eq/=.
+ by rewrite -Hm. + by rewrite -Hm.
+ split; first done. intros i. by rewrite -(dist_None n) -Hm dist_None. + split; first done. intros i. by rewrite -(dist_None n) -Hm dist_None.
- intros [m [E|]]; rewrite dyn_reservation_map_valid_eq dyn_reservation_map_validN_eq /= - intros [m [E|]]; rewrite dyn_reservation_map_valid_eq dyn_reservation_map_validN_eq /=
?cmra_valid_validN; naive_solver eauto using O. ?cmra_valid_validN; naive_solver eauto using O.
- intros n [m [E|]]; rewrite dyn_reservation_map_validN_eq /=; - intros n [m [E|]]; rewrite dyn_reservation_map_validN_eq /=;
naive_solver eauto using cmra_validN_S. naive_solver eauto using cmra_validN_S.
- intros n [m1 [E1|]] [m2 [E2|]]=> //=; rewrite dyn_reservation_map_validN_eq /=. - intros n [m1 [E1|]] [m2 [E2|]]=> //=; rewrite dyn_reservation_map_validN_eq /=.
rewrite {1}/op /cmra_op /=. case_decide; last done. rewrite {1}/op /cmra_op /=. case_decide; last done.
intros [Hm [Hinf Hdisj]]; split; first by eauto using cmra_validN_op_l. intros [Hm [Hinf Hdisj]]; split; first by eauto using cmra_validN_op_l.
split. split.
+ rewrite ->difference_union_distr_r in Hinf. + rewrite ->difference_union_distr_r_L in Hinf.
eapply set_infinite_subseteq; last done. eapply set_infinite_subseteq, Hinf. set_solver.
set_solver. + intros i. move: (Hdisj i). rewrite lookup_op.
+ intros i. move: (Hdisj i). rewrite lookup_op. case: (m1 !! i); case: (m2 !! i); set_solver.
case: (m1 !! i)=> [a|]; last auto. Qed.
move=> [].
{ by case: (m2 !! i). }
set_solver.
Qed.
Canonical Structure dyn_reservation_mapR := Canonical Structure dyn_reservation_mapR :=
Cmra (dyn_reservation_map A) dyn_reservation_map_cmra_mixin. Cmra (dyn_reservation_map A) dyn_reservation_map_cmra_mixin.
Global Instance dyn_reservation_map_cmra_discrete : Global Instance dyn_reservation_map_cmra_discrete :
CmraDiscrete A CmraDiscrete dyn_reservation_mapR. CmraDiscrete A CmraDiscrete dyn_reservation_mapR.
Proof. Proof.
split; first apply _. split; first apply _.
intros [m [E|]]; rewrite dyn_reservation_map_validN_eq dyn_reservation_map_valid_eq //=. intros [m [E|]]; rewrite dyn_reservation_map_validN_eq dyn_reservation_map_valid_eq //=.
by intros [?%cmra_discrete_valid ?]. by intros [?%cmra_discrete_valid ?].
Qed. Qed.
Local Instance dyn_reservation_map_empty_instance : Unit (dyn_reservation_map A) := Local Instance dyn_reservation_map_empty_instance : Unit (dyn_reservation_map A) :=
DynReservationMap ε ε. DynReservationMap ε ε.
Lemma dyn_reservation_map_ucmra_mixin : UcmraMixin (dyn_reservation_map A). Lemma dyn_reservation_map_ucmra_mixin : UcmraMixin (dyn_reservation_map A).
Proof. Proof.
split; simpl. split; simpl.
- rewrite dyn_reservation_map_valid_eq /=. split; [apply ucmra_unit_valid|]. split. - rewrite dyn_reservation_map_valid_eq /=. split; [apply ucmra_unit_valid|]. split.
+ rewrite difference_empty. apply top_infinite. + rewrite difference_empty_L. apply top_infinite.
+ set_solver. + set_solver.
- split; simpl; [by rewrite left_id|by rewrite left_id_L]. - split; simpl; [by rewrite left_id|by rewrite left_id_L].
- do 2 constructor; [apply (core_id_core _)|done]. - do 2 constructor; [apply (core_id_core _)|done].
Qed. Qed.
Canonical Structure dyn_reservation_mapUR := Canonical Structure dyn_reservation_mapUR :=
Ucmra (dyn_reservation_map A) dyn_reservation_map_ucmra_mixin. Ucmra (dyn_reservation_map A) dyn_reservation_map_ucmra_mixin.
Global Instance dyn_reservation_map_data_core_id N a : Global Instance dyn_reservation_map_data_core_id N a :
CoreId a CoreId (dyn_reservation_map_data N a). CoreId a CoreId (dyn_reservation_map_data N a).
Proof. do 2 constructor; simpl; auto. apply core_id_core, _. Qed. Proof. do 2 constructor; simpl; auto. apply core_id_core, _. Qed.
Lemma dyn_reservation_map_data_valid N a : Lemma dyn_reservation_map_data_valid N a :
(dyn_reservation_map_data N a) a. (dyn_reservation_map_data N a) a.
Proof. Proof.
rewrite dyn_reservation_map_valid_eq /= singleton_valid. rewrite dyn_reservation_map_valid_eq /= singleton_valid.
split; first naive_solver. intros Ha. split; first naive_solver. intros Ha.
split; first done. split; last set_solver. split; first done. split; last set_solver.
rewrite difference_empty. apply top_infinite. rewrite difference_empty_L. apply top_infinite.
Qed. Qed.
Lemma dyn_reservation_map_token_valid E : Lemma dyn_reservation_map_token_valid E :
(dyn_reservation_map_token E) set_infinite ( E). (dyn_reservation_map_token E) set_infinite ( E).
Proof. Proof.
rewrite dyn_reservation_map_valid_eq /=. split; first naive_solver. rewrite dyn_reservation_map_valid_eq /=. split; first naive_solver.
intros Hinf. do 2 (split; first done). by left. intros Hinf. do 2 (split; first done). by left.
Qed. Qed.
Lemma dyn_reservation_map_data_op N a b : Lemma dyn_reservation_map_data_op N a b :
dyn_reservation_map_data N (a b) = dyn_reservation_map_data N a dyn_reservation_map_data N b. dyn_reservation_map_data N (a b) = dyn_reservation_map_data N a dyn_reservation_map_data N b.
Proof. Proof.
by rewrite {2}/op /dyn_reservation_map_op_instance /dyn_reservation_map_data /= singleton_op left_id_L. by rewrite {2}/op /dyn_reservation_map_op_instance /dyn_reservation_map_data /= singleton_op left_id_L.
Qed. Qed.
Lemma dyn_reservation_map_data_mono N a b : Lemma dyn_reservation_map_data_mono N a b :
a b dyn_reservation_map_data N a dyn_reservation_map_data N b. a b dyn_reservation_map_data N a dyn_reservation_map_data N b.
Proof. intros [c ->]. rewrite dyn_reservation_map_data_op. apply cmra_included_l. Qed. Proof. intros [c ->]. rewrite dyn_reservation_map_data_op. apply cmra_included_l. Qed.
Global Instance dyn_reservation_map_data_is_op N a b1 b2 : Global Instance dyn_reservation_map_data_is_op N a b1 b2 :
IsOp a b1 b2 IsOp a b1 b2
IsOp' (dyn_reservation_map_data N a) (dyn_reservation_map_data N b1) (dyn_reservation_map_data N b2). IsOp' (dyn_reservation_map_data N a) (dyn_reservation_map_data N b1) (dyn_reservation_map_data N b2).
Proof. rewrite /IsOp' /IsOp=> ->. by rewrite dyn_reservation_map_data_op. Qed. Proof. rewrite /IsOp' /IsOp=> ->. by rewrite dyn_reservation_map_data_op. Qed.
Lemma dyn_reservation_map_token_union E1 E2 : Lemma dyn_reservation_map_token_union E1 E2 :
E1 ## E2 E1 ## E2
dyn_reservation_map_token (E1 E2) = dyn_reservation_map_token E1 dyn_reservation_map_token E2. dyn_reservation_map_token (E1 E2) = dyn_reservation_map_token E1 dyn_reservation_map_token E2.
Proof. Proof.
intros. by rewrite /op /dyn_reservation_map_op_instance intros. by rewrite /op /dyn_reservation_map_op_instance
/dyn_reservation_map_token /= coPset_disj_union // left_id_L. /dyn_reservation_map_token /= coPset_disj_union // left_id_L.
Qed. Qed.
Lemma dyn_reservation_map_token_difference E1 E2 : Lemma dyn_reservation_map_token_difference E1 E2 :
E1 E2 E1 E2
dyn_reservation_map_token E2 = dyn_reservation_map_token E1 dyn_reservation_map_token (E2 E1). dyn_reservation_map_token E2 = dyn_reservation_map_token E1 dyn_reservation_map_token (E2 E1).
Proof. Proof.
intros. rewrite -dyn_reservation_map_token_union; last set_solver. intros. rewrite -dyn_reservation_map_token_union; last set_solver.
by rewrite -union_difference_L. by rewrite -union_difference_L.
Qed. Qed.
Lemma dyn_reservation_map_token_valid_op E1 E2 : Lemma dyn_reservation_map_token_valid_op E1 E2 :
(dyn_reservation_map_token E1 dyn_reservation_map_token E2) (dyn_reservation_map_token E1 dyn_reservation_map_token E2)
E1 ## E2 set_infinite ( (E1 E2)). E1 ## E2 set_infinite ( (E1 E2)).
Proof. Proof.
split. split.
- rewrite dyn_reservation_map_valid_eq /= {1}/op /cmra_op /=. case_decide; last done. - rewrite dyn_reservation_map_valid_eq /= {1}/op /cmra_op /=. case_decide; last done.
naive_solver. naive_solver.
- intros [Hdisj Hinf]. rewrite -dyn_reservation_map_token_union //. - intros [Hdisj Hinf]. rewrite -dyn_reservation_map_token_union //.
apply dyn_reservation_map_token_valid. done. apply dyn_reservation_map_token_valid. done.
Qed. Qed.
Lemma dyn_reservation_map_reserve (Q : dyn_reservation_map A Prop) : Lemma dyn_reservation_map_reserve (Q : dyn_reservation_map A Prop) :
( E, set_infinite E Q (dyn_reservation_map_token E)) ( E, set_infinite E Q (dyn_reservation_map_token E))
ε ~~>: Q. ε ~~>: Q.
Proof. Proof.
intros HQ. apply cmra_total_updateP=> n [mf [Ef|]]; intros HQ. apply cmra_total_updateP=> n [mf [Ef|]];
rewrite left_id {1}dyn_reservation_map_validN_eq /=; last done. rewrite left_id {1}dyn_reservation_map_validN_eq /=; last done.
intros [Hmap [Hinf Hdisj]]. intros [Hmap [Hinf Hdisj]].
(* Pick a fresh set disjoint from the existing tokens [Ef] and map [mf], (* Pick a fresh set disjoint from the existing tokens [Ef] and map [mf],
such that both that set [E1] and the remainder [E2] are infinite. *) such that both that set [E1] and the remainder [E2] are infinite. *)
edestruct (coPset_split_infinite ( (Ef dom coPset mf))) as edestruct (coPset_split_infinite ( (Ef dom coPset mf))) as
(E1 & E2 & HEunion & HEdisj & HE1inf & HE2inf). (E1 & E2 & HEunion & HEdisj & HE1inf & HE2inf).
{ rewrite -difference_difference. { rewrite -difference_difference_L.
apply difference_infinite; first done. by apply difference_infinite, dom_finite. }
apply gset_to_coPset_finite. } exists (dyn_reservation_map_token E1).
exists (dyn_reservation_map_token E1). split; first by apply HQ. clear HQ.
split; first by apply HQ. clear HQ. rewrite dyn_reservation_map_validN_eq /=.
rewrite dyn_reservation_map_validN_eq /=. rewrite coPset_disj_union; last set_solver.
rewrite coPset_disj_union; last set_solver. split; first by rewrite left_id_L. split.
split; first by rewrite left_id. split. - eapply set_infinite_subseteq, HE2inf. set_solver.
- eapply set_infinite_subseteq; last by apply HE2inf. set_solver. - intros i. rewrite left_id_L. destruct (Hdisj i) as [?|Hi]; first by left.
- intros i. rewrite left_id_L. destruct (Hdisj i) as [?|Hi]; first by left. destruct (mf !! i) as [p|] eqn:Hp; last by left.
destruct (mf !! i) as [p|] eqn:Hp; last by left. apply elem_of_dom_2 in Hp. right. set_solver.
apply elem_of_dom_2 in Hp. right. set_solver. Qed.
Qed. Lemma dyn_reservation_map_reserve' :
Lemma dyn_reservation_map_reserve' : ε ~~>: (λ x, E, set_infinite E x = dyn_reservation_map_token E).
ε ~~>: (λ x, E, set_infinite E x = dyn_reservation_map_token E). Proof. eauto using dyn_reservation_map_reserve. Qed.
Proof. eauto using dyn_reservation_map_reserve. Qed.
Lemma dyn_reservation_map_alloc E k a : Lemma dyn_reservation_map_alloc E k a :
k E a dyn_reservation_map_token E ~~> dyn_reservation_map_data k a. k E a dyn_reservation_map_token E ~~> dyn_reservation_map_data k a.
Proof. Proof.
intros ??. apply cmra_total_update=> n [mf [Ef|]] //. intros ??. apply cmra_total_update=> n [mf [Ef|]] //.
rewrite dyn_reservation_map_validN_eq /= {1}/op /cmra_op /=. case_decide; last done. rewrite dyn_reservation_map_validN_eq /= {1}/op /cmra_op /=. case_decide; last done.
rewrite left_id_L {1}left_id. intros [Hmf [Hinf Hdisj]]; split; last split. rewrite left_id_L {1}left_id. intros [Hmf [Hinf Hdisj]]; split; last split.
- destruct (Hdisj (k)) as [Hmfi|]; last set_solver. - destruct (Hdisj k) as [Hmfi|]; last set_solver.
move: Hmfi. rewrite lookup_op lookup_empty left_id_L=> Hmfi. move: Hmfi. rewrite lookup_op lookup_empty left_id_L=> Hmfi.
intros j. rewrite lookup_op. intros j. rewrite lookup_op.
destruct (decide (k = j)) as [<-|]. destruct (decide (k = j)) as [<-|].
+ rewrite Hmfi lookup_singleton right_id_L. by apply cmra_valid_validN. + rewrite Hmfi lookup_singleton right_id_L. by apply cmra_valid_validN.
+ by rewrite lookup_singleton_ne // left_id_L. + by rewrite lookup_singleton_ne // left_id_L.
- eapply set_infinite_subseteq; last done. set_solver. - eapply set_infinite_subseteq, Hinf. set_solver.
- intros j. destruct (decide (k = j)); first set_solver. - intros j. destruct (decide (k = j)); first set_solver.
rewrite lookup_op lookup_singleton_ne //. rewrite lookup_op lookup_singleton_ne //.
destruct (Hdisj j) as [Hmfi|?]; last set_solver. destruct (Hdisj j) as [Hmfi|?]; last set_solver.
move: Hmfi. rewrite lookup_op lookup_empty; auto. move: Hmfi. rewrite lookup_op lookup_empty; auto.
Qed. Qed.
Lemma dyn_reservation_map_updateP P (Q : dyn_reservation_map A Prop) k a : Lemma dyn_reservation_map_updateP P (Q : dyn_reservation_map A Prop) k a :
a ~~>: P a ~~>: P
( a', P a' Q (dyn_reservation_map_data k a')) dyn_reservation_map_data k a ~~>: Q. ( a', P a' Q (dyn_reservation_map_data k a'))
Proof. dyn_reservation_map_data k a ~~>: Q.
intros Hup HP. apply cmra_total_updateP=> n [mf [Ef|]] //. Proof.
rewrite dyn_reservation_map_validN_eq /= left_id_L. intros [Hmf [Hinf Hdisj]]. intros Hup HP. apply cmra_total_updateP=> n [mf [Ef|]] //.
destruct (Hup n (mf !! k)) as (a'&?&?). rewrite dyn_reservation_map_validN_eq /= left_id_L. intros [Hmf [Hinf Hdisj]].
{ move: (Hmf (k)). destruct (Hup n (mf !! k)) as (a'&?&?).
by rewrite lookup_op lookup_singleton Some_op_opM. } { move: (Hmf (k)).
exists (dyn_reservation_map_data k a'); split; first by eauto. by rewrite lookup_op lookup_singleton Some_op_opM. }
rewrite /= left_id_L. split; last split. exists (dyn_reservation_map_data k a'); split; first by eauto.
- intros j. destruct (decide (k = j)) as [<-|]. rewrite /= left_id_L. split; last split.
+ by rewrite lookup_op lookup_singleton Some_op_opM. - intros j. destruct (decide (k = j)) as [<-|].
+ rewrite lookup_op lookup_singleton_ne // left_id_L. + by rewrite lookup_op lookup_singleton Some_op_opM.
move: (Hmf j). rewrite lookup_op. eauto using cmra_validN_op_r. + rewrite lookup_op lookup_singleton_ne // left_id_L.
- done. move: (Hmf j). rewrite lookup_op. eauto using cmra_validN_op_r.
- intros j. move: (Hdisj j). - done.
rewrite !lookup_op !op_None !lookup_singleton_None. naive_solver. - intros j. move: (Hdisj j).
Qed. rewrite !lookup_op !op_None !lookup_singleton_None. naive_solver.
Lemma dyn_reservation_map_update k a b : Qed.
a ~~> b dyn_reservation_map_data k a ~~> dyn_reservation_map_data k b. Lemma dyn_reservation_map_update k a b :
Proof. a ~~> b
rewrite !cmra_update_updateP. eauto using dyn_reservation_map_updateP with subst. dyn_reservation_map_data k a ~~> dyn_reservation_map_data k b.
Qed. Proof.
rewrite !cmra_update_updateP. eauto using dyn_reservation_map_updateP with subst.
Qed.
End cmra. End cmra.
Global Arguments dyn_reservation_mapR : clear implicits. Global Arguments dyn_reservation_mapR : clear implicits.
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment