Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtration by memory model #78

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions _CoqProject
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ prime_eventstruct.v
eventstructure.v
transitionsystem.v
regmachine.v
memory_model.v
34 changes: 31 additions & 3 deletions eventstructure.v
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Notation "w << r" := (write_read_from w r) (at level 0).
Lemma rf_thrdend w : w << ThreadEnd = false.
Proof. by case: w. Qed.

Definition same_loc l l' := lloc l == lloc l'.


(* ************************************************************************* *)
(* Exec Event Structure *)
Expand Down Expand Up @@ -512,7 +514,7 @@ Lemma cfE e1 e2: e1 # e2 = cf_step e1 e2.
Proof.
apply/idP/idP; last by apply: cf_step_cf.
case/cfP=> e1' [e2' [[]]].
case: (boolP (e1' == e1))=> [/eqP-> _|].
case: (boolP (e1' == e1))=> [/eqP-> _ |].
- case: (boolP (e2' == e2))=> [/eqP->_->|]; first (apply/orP; by left).
move/ca_step_last/[apply] => [[x /and3P[/cf_consistr H N + /icf_cf/H]]].
rewrite lt_neqAle=> /andP[] *.
Expand Down Expand Up @@ -548,10 +550,10 @@ Proof.
suff C: ~ m # (fpred m).
case: (boolP (frf m == m))=> [/eqP fE|?].
- rewrite cfE => /orP; rewrite orbb icfxx => [[]] //=.
rewrite fE; case: ifP=> [/eqP//|_]; case: ifP=>//= _; by rewrite orbF => /C.
rewrite fE; case: ifP=> [/eqP//| _]; case: ifP=>//= _; by rewrite orbF => /C.
rewrite cfE icfxx orbb=> /hasP[? /(mem_subseq (filter_subseq _ _))] /=.
by rewrite ?inE=> /orP[/eqP->|/eqP->/C]//; rewrite rff_consist.
move=> /cfP[x [y [[]]]]; case: (eqVneq x m)=> [-> _|].
move=> /cfP[x [y [[]]]]; case: (eqVneq x m)=> [-> _ |].
- by move=> /ca_le L /and4P[_ /eqP<- _ /(le_lt_trans L)]; rewrite ltxx.
move/ca_step_last=> /[apply] [[z /and3P[/[swap]]]].
rewrite /ica !inE=> /pred2P[]-> Cx L.
Expand All @@ -561,6 +563,32 @@ Proof.
by move=> Cy /icf_cf/cf_consist2/(_ Cx Cy); exact/IHm.
Qed.

(* ************************************************************************* *)
(* Writes-Before relation *)
(* ************************************************************************* *)

Definition sca_suffix : E -> seq E := suffix (fica_lt).

Definition contr_loc f : E -> seq E :=
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does contr stands for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contraction

fun e => (f ∘ (same_loc (lab e) \o lab)ᶠ) e.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks a bit cryptic. For example, there are two o notations, both of them denote some kind of composition, but different ))
Also ^f notation is non-standard and a bit misleading.
Finally, you can apply eta conversion here: (fun x => f x) == f

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't apply eta conversion because we use e inside of (same_loc (lab e) \o lab)ᶠ)


Definition contr_wrire f : E -> seq E :=
(is_write \o lab)ᶠ ∘ f ∘ (is_write \o lab)ᶠ.

Definition frf_inv : E -> seq E :=
fun e => [seq x <- dom | frf x == e].

(* wb := [W] ; (po ∪ rf)⁺ |loc ; [W] ∪ [W]; (po ∪ rf)⁺ ; rf⁻ ; [W] \ id *)

Definition fwb : {fsfun E -> seq E with [::]} :=
[fsfun x in (seq_fset tt dom) =>
(
contr_wrire (contr_loc sca_suffix)
strictify (contr_wrire (frf_inv ∘ (contr_loc sca_suffix)))
) x].


End ExecEventStructure.

Canonical es_eqMixin disp E := EqMixin (@eqesP disp E).
Expand Down
45 changes: 45 additions & 0 deletions memory_model.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
From mathcomp Require Import ssreflect ssrfun ssrbool ssrnat seq.
From mathcomp Require Import eqtype choice finfun finmap tuple.
From event_struct Require Import utilities eventstructure inhtype relations.
From event_struct Require Import transitionsystem ident regmachine.


Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.

Section MMConsist.

Context {V : inhType} {disp} {E : identType disp}.

(*Notation n := (@n val).*)
Notation exec_event_struct := (@fin_exec_event_struct V _ E).
Notation cexec_event_struct := (@cexec_event_struct V _ E).

Section GeneralDef.

Variable mm_pred : pred cexec_event_struct.

Inductive mm_config := MMConsist (c : config) of mm_pred (evstr c).

Coercion config_of (mmc : mm_config) :=
let '(MMConsist c _) := mmc in c.

Canonical config_subType := [subType for config_of].

Lemma consist_inj : injective config_of.
Proof. exact: val_inj. Qed.

Variable pgm : parprog (V := V).

Definition mm_eval_ster mmc pr : seq mm_config :=
pmap insub (eval_step pgm mmc pr).

End GeneralDef.

Export FinClosure.

Definition ra_consist (es : cexec_event_struct):=
all (fun x => x \notin t_closure (fwb es) x) (dom es).

End MMConsist.
18 changes: 11 additions & 7 deletions regmachine.v
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Definition ltr_thrd_sem (l : option (@label V V)) pgm st1 st2 : bool :=
| _, _ => false
end.

Section AddHole.

Variable (es : cexec_event_struct).
Notation ffpred := (fpred es).
Notation ffrf := (frf es).
Expand Down Expand Up @@ -218,21 +220,23 @@ Definition add_hole
end
else [::].

End AddHole.

Variable prog : parprog.

Definition fresh_tid (c : config) :=
foldr maxn 0 [seq (snd x).+1 | x <- fgraph (fmap_of_fsfun c)].

Definition eval_step (c : config) pr : seq config :=
let: Config es tmap := c in
let: (conf, tid) := tmap pr in
let: tid := if pr \in dom es then tid else fresh_tid c in
let: (l, cont_st) := thrd_sem (nth empty_prog prog tid) conf in
let: Config ces tmap := c in
let: (conf, tid) := tmap pr in
let: tid := if pr \in dom ces then tid else fresh_tid c in
let: (l, cont_st) := thrd_sem (nth empty_prog prog tid) conf in
if l is Some l then do
(e, v) <- add_hole l pr;
[:: Config e [fsfun c with fresh_id |-> (cont_st v, tid)]]
(e, v) <- add_hole ces l pr;
[:: Config e [fsfun c with (fresh_seq (dom ces)) |-> (cont_st v, tid)]]
else
[:: Config es [fsfun c with pr |-> (cont_st inh, tid)]].
[:: Config ces [fsfun c with pr |-> (cont_st inh, tid)]].

End RegMachine.

24 changes: 22 additions & 2 deletions relations.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ Local Open Scope ra_terms.
Definition sfrel {T : eqType} (f : T -> seq T) : rel T :=
[rel a b | a \in f b].



Section Strictify.

Context {T : eqType}.
Expand Down Expand Up @@ -361,3 +359,25 @@ End FinRTClosure.

End FinClosure.

Section Operations.

Context {T : Type}.
Variables (f g : T -> seq T) (p : pred T).

Definition composition :=
fun x => do y <- g x; f y.
Copy link
Collaborator

@eupp eupp Apr 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is Kleisli composition. You can use notation (>=>) if you will import monae.


Definition fun_of_pred :=
fun x => if p x then [:: x] else [::].

Definition funion :=
fun x => f x ++ g x.

End Operations.

Notation "p 'ᶠ'" := (fun_of_pred p) (at level 10).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we were discussing that this is related to "tests" from Kleene Algebras with Tests, but currently we cannot use the notation from relation-algebra. So until I will fix the blocking problem in relation-algebra let's either:

  1. do not use any notation for this;
  2. use the same notation as in relation-algebra, so later we'll be able to migrate smoothly.

I prefer the second solution.

Notation "f ∘ g" := (composition f g) (at level 100, right associativity).
Notation "f ∪ g" := (funion f g) (at level 100).



2 changes: 1 addition & 1 deletion utilities.v
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Qed.

End ReflectConnectives.

Notation "'do' i <- s ; E" := (flatten (map (fun i => E) s)) (at level 10, i pattern).
Notation "'do' i <- s ; E" := (flatten (map (fun i => E) s)) (at level 100, i pattern).

Section RelationOnSeq.

Expand Down