Skip to content
Snippets Groups Projects
Commit 3f61f05d authored by Ralf Jung's avatar Ralf Jung
Browse files

make the global functor stuff in the various constructions more uniform;...

make the global functor stuff in the various constructions more uniform; change it such that barrier/proof does not have to repeat the functors it needs
parent 82cc2528
No related branches found
No related tags found
No related merge requests found
...@@ -6,17 +6,17 @@ From barrier Require Export barrier. ...@@ -6,17 +6,17 @@ From barrier Require Export barrier.
From barrier Require Import protocol. From barrier Require Import protocol.
Import uPred. Import uPred.
(** The monoids we need. *) (** The CMRAs we need. *)
(* Not bundling heapG, as it may be shared with other users. *) (* Not bundling heapG, as it may be shared with other users. *)
Class barrierG Σ := BarrierG { Class barrierG Σ := BarrierG {
barrier_stsG :> stsG heap_lang Σ sts; barrier_stsG :> stsG heap_lang Σ sts;
barrier_savedPropG :> savedPropG heap_lang Σ idCF; barrier_savedPropG :> savedPropG heap_lang Σ idCF;
}. }.
(** The Functors we need. *)
Definition barrierGF : rFunctors := [stsGF sts; agreeRF idCF]. Definition barrierGF : rFunctors := [stsGF sts; agreeRF idCF].
(* Show and register that they match. *)
Instance inGF_barrierG Instance inGF_barrierG `{H : inGFs heap_lang Σ barrierGF} : barrierG Σ.
`{inGF heap_lang Σ (stsGF sts), inGF heap_lang Σ (agreeRF idCF)} : barrierG Σ. Proof. destruct H as (?&?&?). split; apply _. Qed.
Proof. split; apply _. Qed.
(** Now we come to the Iris part of the proof. *) (** Now we come to the Iris part of the proof. *)
Section proof. Section proof.
......
...@@ -8,14 +8,14 @@ Import uPred. ...@@ -8,14 +8,14 @@ Import uPred.
predicates over finmaps instead of just ownP. *) predicates over finmaps instead of just ownP. *)
Definition heapR : cmraT := mapR loc (fracR (dec_agreeR val)). Definition heapR : cmraT := mapR loc (fracR (dec_agreeR val)).
Definition heapGF : rFunctor := authGF heapR.
(** The CMRA we need. *)
Class heapG Σ := HeapG { Class heapG Σ := HeapG {
heap_inG : inG heap_lang Σ (authR heapR); heap_inG :> authG heap_lang Σ heapR;
heap_name : gname heap_name : gname
}. }.
Instance heap_authG `{i : heapG Σ} : authG heap_lang Σ heapR := (** The Functor we need. *)
{| auth_inG := heap_inG |}. Definition heapGF : rFunctor := authGF heapR.
Definition to_heap : state heapR := fmap (λ v, Frac 1 (DecAgree v)). Definition to_heap : state heapR := fmap (λ v, Frac 1 (DecAgree v)).
Definition of_heap : heapR state := Definition of_heap : heapR state :=
......
...@@ -14,13 +14,14 @@ Definition join : val := ...@@ -14,13 +14,14 @@ Definition join : val :=
| InjL <> => '"join" '"c" | InjL <> => '"join" '"c"
end. end.
(** The monoids we need. *) (** The CMRA we need. *)
(* Not bundling heapG, as it may be shared with other users. *) (* Not bundling heapG, as it may be shared with other users. *)
Class spawnG Σ := SpawnG { Class spawnG Σ := SpawnG {
spawn_tokG :> inG heap_lang Σ (exclR unitC); spawn_tokG :> inG heap_lang Σ (exclR unitC);
}. }.
(** The functor we need. *)
Definition spawnGF : rFunctors := [constRF (exclR unitC)]. Definition spawnGF : rFunctors := [constRF (exclR unitC)].
(* Show and register that they match. *)
Instance inGF_spawnG Instance inGF_spawnG
`{inGF heap_lang Σ (constRF (exclR unitC))} : spawnG Σ. `{inGF heap_lang Σ (constRF (exclR unitC))} : spawnG Σ.
Proof. split. apply: inGF_inG. Qed. Proof. split. apply: inGF_inG. Qed.
......
...@@ -2,13 +2,15 @@ From algebra Require Export auth upred_tactics. ...@@ -2,13 +2,15 @@ From algebra Require Export auth upred_tactics.
From program_logic Require Export invariants global_functor. From program_logic Require Export invariants global_functor.
Import uPred. Import uPred.
(* The CMRA we need. *)
Class authG Λ Σ (A : cmraT) `{Empty A} := AuthG { Class authG Λ Σ (A : cmraT) `{Empty A} := AuthG {
auth_inG :> inG Λ Σ (authR A); auth_inG :> inG Λ Σ (authR A);
auth_identity :> CMRAIdentity A; auth_identity :> CMRAIdentity A;
auth_timeless :> CMRADiscrete A; auth_timeless :> CMRADiscrete A;
}. }.
(* The Functor we need. *)
Definition authGF (A : cmraT) : rFunctor := constRF (authR A). Definition authGF (A : cmraT) : rFunctor := constRF (authR A).
(* Show and register that they match. *)
Instance authGF_inGF (A : cmraT) `{inGF Λ Σ (authGF A)} Instance authGF_inGF (A : cmraT) `{inGF Λ Σ (authGF A)}
`{CMRAIdentity A, CMRADiscrete A} : authG Λ Σ A. `{CMRAIdentity A, CMRADiscrete A} : authG Λ Σ A.
Proof. split; try apply _. apply: inGF_inG. Qed. Proof. split; try apply _. apply: inGF_inG. Qed.
......
...@@ -5,6 +5,12 @@ Module rFunctors. ...@@ -5,6 +5,12 @@ Module rFunctors.
| nil : rFunctors | nil : rFunctors
| cons : rFunctor rFunctors rFunctors. | cons : rFunctor rFunctors rFunctors.
Coercion singleton (F : rFunctor) : rFunctors := cons F nil. Coercion singleton (F : rFunctor) : rFunctors := cons F nil.
Fixpoint fold_right {A} (f : rFunctor A A) (a : A) (Fs : rFunctors) : A :=
match Fs with
| nil => a
| cons F Fs => f F (fold_right f a Fs)
end.
End rFunctors. End rFunctors.
Notation rFunctors := rFunctors.rFunctors. Notation rFunctors := rFunctors.rFunctors.
...@@ -58,3 +64,16 @@ Proof. by exists 0. Qed. ...@@ -58,3 +64,16 @@ Proof. by exists 0. Qed.
Instance inGF_further {Λ Σ} (F F': rFunctor) : Instance inGF_further {Λ Σ} (F F': rFunctor) :
inGF Λ Σ F inGF Λ (rFunctorG.cons F' Σ) F. inGF Λ Σ F inGF Λ (rFunctorG.cons F' Σ) F.
Proof. intros [i ?]. by exists (S i). Qed. Proof. intros [i ?]. by exists (S i). Qed.
(** For modules that need more than one functor, we offer a typeclass
[inGFs] to demand a list of rFunctor to be available. We do
*not* register any instances that go from there to [inGF], to
avoid cycles. *)
Class inGFs (Λ : language) (Σ : rFunctorG) (Fs : rFunctors) :=
InGFs : (rFunctors.fold_right (λ F T, inGF Λ Σ F * T) () Fs)%type.
Instance inGFs_nil {Λ Σ} : inGFs Λ Σ [].
Proof. exact tt. Qed.
Instance inGFs_cons {Λ Σ} F Fs :
inGF Λ Σ F inGFs Λ Σ Fs inGFs Λ Σ (rFunctors.cons F Fs).
Proof. split; done. Qed.
...@@ -2,13 +2,15 @@ From algebra Require Export sts upred_tactics. ...@@ -2,13 +2,15 @@ From algebra Require Export sts upred_tactics.
From program_logic Require Export invariants global_functor. From program_logic Require Export invariants global_functor.
Import uPred. Import uPred.
(** The CMRA we need. *)
Class stsG Λ Σ (sts : stsT) := StsG { Class stsG Λ Σ (sts : stsT) := StsG {
sts_inG :> inG Λ Σ (stsR sts); sts_inG :> inG Λ Σ (stsR sts);
sts_inhabited :> Inhabited (sts.state sts); sts_inhabited :> Inhabited (sts.state sts);
}. }.
Coercion sts_inG : stsG >-> inG. Coercion sts_inG : stsG >-> inG.
(** The Functor we need. *)
Definition stsGF (sts : stsT) : rFunctor := constRF (stsR sts). Definition stsGF (sts : stsT) : rFunctor := constRF (stsR sts).
(* Show and register that they match. *)
Instance inGF_stsG sts `{inGF Λ Σ (stsGF sts)} Instance inGF_stsG sts `{inGF Λ Σ (stsGF sts)}
`{Inhabited (sts.state sts)} : stsG Λ Σ sts. `{Inhabited (sts.state sts)} : stsG Λ Σ sts.
Proof. split; try apply _. apply: inGF_inG. Qed. Proof. split; try apply _. apply: inGF_inG. Qed.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment