Commit 3d310509 authored by charguer's avatar charguer

renaming_fmap

parent 556f9fd9
LibState
Fmap
LambdaSemantics
SepFunctor
LambdaSep
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ Require Export LibFix LambdaSep.
Open Scope heap_scope.
(********************************************************************)
(* ********************************************************************** *)
(* ** Type of a formula *)
(** A formula is a binary relation relating a pre-condition
......@@ -26,7 +26,7 @@ Global Instance formula_inhab : Inhab formula.
Proof using. apply (prove_Inhab (fun _ _ => True)). Qed.
(********************************************************************)
(* ********************************************************************** *)
(* ** The [local] predicate *)
(** Nested applications [local] are redundant *)
......@@ -56,10 +56,10 @@ Proof using. intros. unfolds. rewrite~ local_local. Qed.
Hint Resolve local_is_local.
(********************************************************************)
(* ********************************************************************** *)
(* ** Characteristic formula generator *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Input language for the characteristic formula generator,
where functions are named by a let-binding. *)
......@@ -102,7 +102,7 @@ Fixpoint trm_of_Trm (t : Trm) : trm :=
Coercion trm_of_Trm : Trm >-> trm.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(** Size function used as measure for the CF generator:
it computes the size of a term, where all values counting
for one unit, including closures viewed as values. *)
......@@ -123,7 +123,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the [app] predicate *)
(** The proposition [app f v H Q] asserts that the application
......@@ -133,7 +133,7 @@ Definition app f v H Q :=
triple (trm_app f v) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of CF blocks *)
(** These auxiliary definitions give the characteristic formula
......@@ -160,7 +160,7 @@ Definition cf_fix (F1of : val -> val -> formula)
(F2of F) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Instance of [app] for primitive operations *)
Lemma app_ref : forall v,
......@@ -176,7 +176,7 @@ Lemma app_set : forall w l v,
Proof using. applys rule_set. Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the CF generator *)
(** The CF generator is a recursive function, defined using the
......@@ -218,10 +218,10 @@ Ltac simpl_cf :=
rewrite cf_unfold; unfold cf_def.
(********************************************************************)
(* ********************************************************************** *)
(* ** Soundness proof *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Two substitution lemmas for the soundness proof *)
Hint Extern 1 (measure Trm_size _ _) => hnf; simpl; math.
......@@ -248,7 +248,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Soundness of the CF generator *)
Lemma cf_local : forall T,
......
(********************************************************************)
(* ********************************************************************** *)
(* ** Completeness proof *)
(* TO BE COMPLETED *)
......@@ -23,7 +23,7 @@ Lemma local_name : forall F (H:hprop) (Q:val->hprop),
Proof.
introv L M. rewrite L. intros m Hm.
exists (= m) \[] Q. splits~.
{ exists~ m state_empty. }
{ exists~ m fmap_empty. }
{ intros h. applys himpl_cancel_r. intros h' Hh'. applys~ hprop_gc_intro. }
Qed.
......@@ -71,7 +71,7 @@ Theorem cf_complete_wrt_semantics : forall (T:Trm) m m' v',
Proof using.
introv H. gen_eq t: (trm_of_Trm T); gen T; induction H; intros T E.
{ simpl_Trm. simpl_cf. applys local_erase. hnf.
intros m' E. subst. exists~ (state_empty:state) m. }
intros m' E. subst. exists~ (fmap_empty:state) m. }
{ simpl_Trm. simpl_cf. applys local_erase. hnf.
case_if; applys~ IHred. }
{ simpl_Trm.
......
......@@ -15,7 +15,7 @@ Require Export LibFix LambdaSepCredits. (* MODIFIED FOR CREDITS *)
Open Scope heap_scope.
(********************************************************************)
(* ********************************************************************** *)
(* ** Type of a formula *)
(** A formula is a binary relation relating a pre-condition
......@@ -27,7 +27,7 @@ Global Instance formula_inhab : Inhab formula.
Proof using. apply (prove_Inhab (fun _ _ => True)). Qed.
(********************************************************************)
(* ********************************************************************** *)
(* ** The [local] predicate *)
......@@ -58,10 +58,10 @@ Proof using. intros. unfolds. rewrite~ local_local. Qed.
Hint Resolve local_is_local.
(********************************************************************)
(* ********************************************************************** *)
(* ** Characteristic formula generator *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Input language for the characteristic formula generator,
where functions are named by a let-binding. *)
......@@ -104,7 +104,7 @@ Fixpoint trm_of_Trm (t : Trm) : trm :=
Coercion trm_of_Trm : Trm >-> trm.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(** Size function used as measure for the CF generator:
it computes the size of a term, where all values counting
for one unit, including closures viewed as values. *)
......@@ -125,7 +125,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the [app] predicate *)
(** The proposition [app f v H Q] asserts that the application
......@@ -135,7 +135,7 @@ Definition app f v H Q :=
triple (trm_app f v) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of CF blocks *)
(** These auxiliary definitions give the characteristic formula
......@@ -167,7 +167,7 @@ Definition cf_fix (F1of : val -> val -> formula)
(F2of F) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Instance of [app] for primitive operations *)
Lemma app_ref : forall v,
......@@ -183,7 +183,7 @@ Lemma app_set : forall w l v,
Proof using. applys rule_set. Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the CF generator *)
(** The CF generator is a recursive function, defined using the
......@@ -225,10 +225,10 @@ Ltac simpl_cf :=
rewrite cf_unfold; unfold cf_def.
(********************************************************************)
(* ********************************************************************** *)
(* ** Soundness proof *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Two substitution lemmas for the soundness proof *)
Hint Extern 1 (measure Trm_size _ _) => hnf; simpl; math.
......@@ -255,7 +255,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Soundness of the CF generator *)
Lemma cf_local : forall T,
......
......@@ -9,10 +9,10 @@ License: MIT.
*)
Set Implicit Arguments.
Require Export LibCore LibState.
Require Export LibCore Fmap.
(************************************************************)
(* ********************************************************************** *)
(* * Source language syntax *)
(** Representation of variables and locations *)
......@@ -66,17 +66,17 @@ with subst_trm (y : var) (w : val) (t : trm) : trm :=
(************************************************************)
(* ********************************************************************** *)
(* * Source language semantics *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(** Big-step evaluation *)
Section Red.
Definition state := state loc val.
Definition state := fmap loc val.
Local Open Scope state_scope.
Local Open Scope fmap_scope.
Coercion val_prim : prim >-> val.
Coercion trm_val : val >-> trm.
......@@ -101,24 +101,24 @@ Inductive red : state -> trm -> state -> val -> Prop :=
red m1 (trm_app v1 v2) m2 r
| red_ref : forall ma mb v l,
l <> null ->
mb = (state_single l v) ->
mb = (fmap_single l v) ->
\# ma mb ->
red ma (prim_ref v) (mb \+ ma) (val_loc l)
| red_get : forall m l v,
state_data m l = Some v ->
fmap_data m l = Some v ->
red m (prim_get (val_loc l)) m v
| red_set : forall m m' l v,
m' = state_update m l v ->
m' = fmap_update m l v ->
red m (prim_set (val_pair (val_loc l) v)) m' val_unit.
End Red.
(*------------------------------------------------------------------*)
(* ** Tactic [state_red] for proving [red] goals modulo
(* ---------------------------------------------------------------------- *)
(* ** Tactic [fmap_red] for proving [red] goals modulo
equalities between states *)
Ltac state_red_base tt ::=
Ltac fmap_red_base tt ::=
match goal with H: red _ ?t _ _ |- red _ ?t _ _ =>
applys_eq H 2 4; try state_eq end.
applys_eq H 2 4; try fmap_eq end.
......@@ -16,18 +16,18 @@ License: MIT.
Set Implicit Arguments.
Require Export LambdaSemantics SepFunctor.
Open Scope state_scope.
Open Scope fmap_scope.
Ltac auto_star ::= jauto.
(********************************************************************)
(* ********************************************************************** *)
(* * Construction of core of the logic *)
Module SepBasicCore.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Types *)
Definition heap : Type := (state)%type.
......@@ -35,24 +35,24 @@ Definition heap : Type := (state)%type.
Definition hprop := heap -> Prop.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Properties of heaps *)
(** Definitions used for uniformity with other
instantiation of the functor *)
Notation "'heap_empty'" := (state_empty : heap) : heap_scope.
Notation "'heap_empty'" := (fmap_empty : heap) : heap_scope.
Open Scope heap_scope.
Notation "h1 \u h2" := (state_union h1 h2)
Notation "h1 \u h2" := (fmap_union h1 h2)
(at level 51, right associativity) : heap_scope.
Definition heap_union_empty_l := state_union_empty_l.
Definition heap_union_empty_r := state_union_empty_r.
Definition heap_union_comm := state_union_comm_disjoint.
Definition heap_union_empty_l := fmap_union_empty_l.
Definition heap_union_empty_r := fmap_union_empty_r.
Definition heap_union_comm := fmap_union_comm_disjoint.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Operators *)
(* \[] *)
......@@ -84,7 +84,7 @@ Definition hprop_gc :=
hprop_exists (fun (H:hprop) => H).
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Notation *)
Notation "\[]" := (hprop_empty)
......@@ -97,21 +97,21 @@ Notation "\GC" := (hprop_gc) : heap_scope.
Open Scope heap_scope.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Tactic for automation *)
(* TODO: check how much is really useful *)
Hint Extern 1 (_ = _ :> heap) => state_eq.
Hint Extern 1 (_ = _ :> heap) => fmap_eq.
Tactic Notation "state_disjoint_pre" :=
Tactic Notation "fmap_disjoint_pre" :=
subst; rew_disjoint; jauto_set.
Hint Extern 1 (\# _ _) => state_disjoint_pre.
Hint Extern 1 (\# _ _ _) => state_disjoint_pre.
Hint Extern 1 (\# _ _) => fmap_disjoint_pre.
Hint Extern 1 (\# _ _ _) => fmap_disjoint_pre.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Properties of empty *)
Lemma hprop_empty_intro :
......@@ -124,7 +124,7 @@ Lemma hprop_empty_inv : forall h,
Proof using. auto. Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Properties of star *)
Section Properties.
......@@ -159,7 +159,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Interaction of star with other operators *)
Lemma hprop_star_exists : forall A (J:A->hprop) H,
......@@ -181,19 +181,19 @@ End Properties.
End SepBasicCore.
(********************************************************************)
(* ********************************************************************** *)
(* * Properties of the logic *)
Module Export SepBasicSetup := SepLogicSetup SepBasicCore.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Singleton heap *)
(** r ~~> v *)
Definition hprop_single (l:loc) (v:val) : hprop :=
fun h => h = state_single l v /\ l <> null.
fun h => h = fmap_single l v /\ l <> null.
Notation "l '~~>' v" := (hprop_single l v)
(at level 32, no associativity) : heap_scope.
......@@ -202,7 +202,7 @@ Lemma hprop_star_single_same_loc_disjoint : forall (l:loc) (v1 v2:val),
(l ~~> v1) \* (l ~~> v2) ==> \[False].
Proof using.
intros. unfold hprop_single. intros h (h1&h2&E1&E2&D&E). false.
subst. applys* state_single_same_loc_disjoint.
subst. applys* fmap_single_same_loc_disjoint.
Qed.
Global Opaque hprop_single.
......@@ -215,11 +215,11 @@ Ltac hcancel_hook H ::=
end.
(********************************************************************)
(* ********************************************************************** *)
(* * Reasoning Rules *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of triples *)
Definition triple t H Q :=
......@@ -230,7 +230,7 @@ Definition triple t H Q :=
/\ (Q v \* \GC \* H') h'.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Structural rules *)
Lemma rule_extract_exists : forall t (A:Type) (J:A->hprop) Q,
......@@ -285,7 +285,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Term rules *)
Lemma rule_val : forall v H Q,
......@@ -357,8 +357,8 @@ Lemma rule_ref : forall v,
triple (prim_ref v) \[] (fun r => Hexists l, \[r = val_loc l] \* l ~~> v).
Proof using.
intros. intros HF h N.
forwards~ (l&Dl&Nl): (state_disjoint_new null h v).
sets h1': (state_single l v).
forwards~ (l&Dl&Nl): (fmap_disjoint_new null h v).
sets h1': (fmap_single l v).
exists (h1' \u h) (val_loc l). splits~.
{ applys~ red_ref. }
{ exists h1' h. split.
......@@ -371,7 +371,7 @@ Lemma rule_get : forall v l,
Proof using.
intros. intros HF h N. exists h v. splits~.
{ applys red_get. destruct N as (?&?&(?&?)&?&?&?).
subst h. applys~ state_union_single_read. }
subst h. applys~ fmap_union_single_read. }
{ rew_heap. rewrite hprop_star_pure. split~. hhsimpl~. }
Qed.
......@@ -379,23 +379,23 @@ Lemma rule_set : forall w l v,
triple (prim_set (val_pair (val_loc l) w)) (l ~~> v) (fun r => \[r = val_unit] \* l ~~> w).
Proof using.
intros. intros HF h N. destruct N as (h1&h2&(N0&N1)&N2&N3&N4).
hnf in N1. sets h1': (state_single l w).
hnf in N1. sets h1': (fmap_single l w).
exists (h1' \u h2) val_unit. splits~.
{ applys red_set. subst h h1. applys~ state_union_single_write. }
{ applys red_set. subst h h1. applys~ fmap_union_single_write. }
{ rew_heap. rewrite hprop_star_pure. split~.
{ exists h1' h2. splits~.
{ hnfs~. }
{ hhsimpl~. }
{ subst h1. applys~ state_disjoint_single_set v. } } }
{ subst h1. applys~ fmap_disjoint_single_set v. } } }
Qed.
End RulesPrimitiveOps.
(********************************************************************)
(* ********************************************************************** *)
(* * Bonus *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Triples satisfy the [local] predicate *)
Lemma is_local_triple : forall t,
......@@ -415,7 +415,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Alternative, low-level definition of triples *)
Definition triple' t H Q :=
......@@ -438,11 +438,11 @@ Proof using.
rewrite <- hprop_star_assoc in R2.
destruct R2 as (h1''&h2'&N0&N1&N2&N3). subst h2'.
destruct N0 as (h1'&h3'&T0&T1&T2&T3).
exists h1' h3' v. splits~. { state_red. } }
exists h1' h3' v. splits~. { fmap_red. } }
{ introv (h1&h2&N1&N2&D&U).
forwards~ (h1'&h3'&v&R1&R2&R3): M h1 h2.
exists (h1' \u h3' \u h2) v. splits~.
{ state_red. }
{ fmap_red. }
{ exists~ h1' (h3' \u h2). splits~.
exists h3' h2. splits~. } }
Qed.
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -16,7 +16,7 @@ Require Export LibFix MLSep.
Open Scope heap_scope.
(********************************************************************)
(* ********************************************************************** *)
(* ** Type of a formula *)
(** A formula is a binary relation relating a pre-condition
......@@ -28,7 +28,7 @@ Global Instance formula_inhab : Inhab formula.
Proof using. apply (prove_Inhab (fun _ _ => True)). Qed.
(********************************************************************)
(* ********************************************************************** *)
(* ** The [local] predicate *)
(** Nested applications [local] are redundant *)
......@@ -58,10 +58,10 @@ Proof using. intros. unfolds. rewrite~ local_local. Qed.
Hint Resolve local_is_local.
(********************************************************************)
(* ********************************************************************** *)
(* ** Characteristic formula generator *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Input language for the characteristic formula generator,
where functions are named by a let-binding. *)
......@@ -132,7 +132,7 @@ Fixpoint Trm_of_trm (t : trm) : Trm :=
end.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(** Size function used as measure for the CF generator:
it computes the size of a term, where all values counting
for one unit, including closures viewed as values. *)
......@@ -156,7 +156,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(** Proof that the reciprocal translation is indeed the reciprocal. *)
Section Reciprocal.
......@@ -203,7 +203,7 @@ Qed.
End Reciprocal.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the [app] predicate *)
(** The proposition [app f vs H Q] asserts that the application
......@@ -213,7 +213,7 @@ Definition app f vs H Q :=
triple (trm_app f vs) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of CF blocks *)
(** These auxiliary definitions give the characteristic formula
......@@ -270,7 +270,7 @@ Definition cf_fail : formula := fun H Q =>
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Instance of [app] for primitive operations *)
(* LATER
......@@ -290,7 +290,7 @@ Proof using. applys rule_set. Qed.
*)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the CF generator *)
(** The CF generator is a recursive function, defined using the
......@@ -348,10 +348,10 @@ Ltac simpl_cf :=
rewrite cf_unfold; unfold cf_def.
(********************************************************************)
(* ********************************************************************** *)
(* ** Soundness proof *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Two substitution lemmas for the soundness proof *)
Hint Extern 1 (measure Trm_size _ _) => hnf; simpl; math.
......@@ -380,7 +380,7 @@ Proof using.
Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Soundness of the CF generator *)
Lemma cf_local : forall T,
......@@ -443,7 +443,7 @@ Theorem cf_sound_final : forall (t:Trm) H Q,
Proof using. intros. applys* cf_sound_induction. Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Soundness result, practical versions *)
Theorem cf_sound : forall (t:trm) H Q,
......@@ -472,7 +472,7 @@ Proof using. introv EF M. applys* cf_sound_app. Qed.
(********************************************************************)
(* ********************************************************************** *)
(* ** CF tactics *)
Module MLCFTactics.
......@@ -480,7 +480,7 @@ Module MLCFTactics.
Ltac xlocal_core tt ::=
try first [ applys local_is_local | applys is_local_triple | assumption ].
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Notation for characteristic formulae *)
Notation "'Val' v" :=
......
......@@ -21,11 +21,11 @@ Open Scope charac.
Ltac auto_star ::= jauto.
(********************************************************************)
(* ********************************************************************** *)
(* CF with Lifting *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Type of a formula *)
(** A formula is a binary relation relating a pre-condition
......@@ -64,7 +64,7 @@ Definition App (f:func) (Vs:dyns) `{Enc A} H (Q:A->hprop) :=
Triple (trm_app f (encs Vs)) H Q.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** The [local] predicate *)
Lemma Local_local : forall A `{EA:Enc A} (F:formula),
......@@ -85,7 +85,7 @@ Lemma App_is_local : forall (f:func) (Vs:dyns) A `{EA:Enc A},
Proof using. intros. unfold App. applys Triple_is_local. Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of CF blocks *)
(** These auxiliary definitions give the characteristic formula
......@@ -137,7 +137,7 @@ Definition Cf_fail : formula := fun `{Enc A} H (Q:A->hprop) =>
False.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Instance of [app] for primitive operations *)
(* LATER
......@@ -154,7 +154,7 @@ Lemma app_set : forall A1 A2 `{EA1:Enc A1} `{EA2:Enc A2} l (V:A1) (W:A2),
Proof using. intros. applys~ Rule_set. Qed.
*)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Auxiliary *)
Lemma Trm_size_Subst : forall t E,
......@@ -165,7 +165,7 @@ Qed.
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Definition of the CF generator *)
Definition Cf_def Cf (t:Trm) : formula :=
......@@ -226,10 +226,10 @@ Ltac simpl_Cf :=
rewrite Cf_unfold; unfold Cf_def.
(********************************************************************)
(* ********************************************************************** *)
(* ** Soundness proof *)
(*------------------------------------------------------------------*)
(* ---------------------------------------------------------------------- *)
(* ** Two substitution lemmas for the soundness proof *)