Commit 9d43893c authored by Daniël Louwrink's avatar Daniël Louwrink

start updating typing rules

parent 01ec9471
...@@ -15,16 +15,14 @@ Section properties. ...@@ -15,16 +15,14 @@ Section properties.
Implicit Types Γ : gmap string (ltty Σ). Implicit Types Γ : gmap string (ltty Σ).
(** Variable properties *) (** Variable properties *)
(* TODO(TYRULES) *)
Lemma ltyped_var Γ (x : string) A : Lemma ltyped_var Γ (x : string) A :
Γ !! x = Some A Γ x : A <[x:=copy- A]>%lty Γ. Γ !! x = Some A Γ x : A <[x := (copy- A)%lty]> Γ.
Proof. Proof.
iIntros (HΓx) "!>"; iIntros (vs) "HΓ /=". iIntros (HΓx) "!>"; iIntros (vs) "HΓ /=".
iDestruct (env_ltyped_lookup with "HΓ") as (v Hx) "[HA HΓ]"; first done. (* iDestruct (env_ltyped_lookup with "HΓ") as (v ->) "[HA HΓ]"; first done. *)
rewrite Hx. iApply wp_value. (* iApply wp_value. eauto with iFrame. *)
iDestruct (coreP_intro with "HA") as "#HAc". iFrame "HA". Admitted.
iEval (rewrite -insert_delete -(insert_id vs x v) //).
by iApply (env_ltyped_insert _ _ x).
Qed.
(** Subtyping *) (** Subtyping *)
Theorem ltyped_subsumption Γ Γ2 e τ1 τ2 : Theorem ltyped_subsumption Γ Γ2 e τ1 τ2 :
...@@ -196,25 +194,26 @@ Section properties. ...@@ -196,25 +194,26 @@ Section properties.
iRight. iExists v. auto. iRight. iExists v. auto.
Qed. Qed.
Definition paircase : val := λ: "pair" "left" "right", (* TODO(TYRULES) *)
Case "pair" "left" "right". Lemma ltyped_case Γ1 Γ2 Γ3 e1 e2 e3 A1 A2 B :
(Γ1 e1 : A1 + A2 Γ2) -
Lemma ltyped_paircase A1 A2 B : (Γ2 e2 : A1 B Γ3) -
paircase : A1 + A2 (A1 B) (A2 B) B. (Γ2 e3 : A2 B Γ3) -
(Γ1 Case e1 e2 e3 : B Γ3).
Proof. Proof.
iIntros (vs) "!> HΓ /=". iApply wp_value. (* iIntros (vs) "!> HΓ /=". iApply wp_value. *)
iSplitL; last by iApply env_ltyped_empty. (* iSplitL; last by iApply env_ltyped_empty. *)
rewrite /paircase. iIntros "!>" (p) "Hp". wp_pures. (* rewrite /paircase. iIntros "!>" (p) "Hp". wp_pures. *)
iIntros (f_left) "Hleft". wp_pures. (* iIntros (f_left) "Hleft". wp_pures. *)
iIntros (f_right) "Hright". wp_pures. (* iIntros (f_right) "Hright". wp_pures. *)
iDestruct "Hp" as "[Hp|Hp]". (* iDestruct "Hp" as "[Hp|Hp]". *)
- iDestruct "Hp" as (w1 ->) "Hp". wp_pures. (* - iDestruct "Hp" as (w1 ->) "Hp". wp_pures. *)
wp_apply (wp_wand with "(Hleft [Hp //])"). (* wp_apply (wp_wand with "(Hleft [Hp //])"). *)
iIntros (v) "HB". iApply "HB". (* iIntros (v) "HB". iApply "HB". *)
- iDestruct "Hp" as (w2 ->) "Hp". wp_pures. (* - iDestruct "Hp" as (w2 ->) "Hp". wp_pures. *)
wp_apply (wp_wand with "(Hright [Hp //])"). (* wp_apply (wp_wand with "(Hright [Hp //])"). *)
iIntros (v) "HB". iApply "HB". (* iIntros (v) "HB". iApply "HB". *)
Qed. Admitted.
(** Universal Properties *) (** Universal Properties *)
Lemma ltyped_tlam Γ e k (C : lty Σ k ltty Σ) : Lemma ltyped_tlam Γ e k (C : lty Σ k ltty Σ) :
...@@ -242,37 +241,42 @@ Section properties. ...@@ -242,37 +241,42 @@ Section properties.
wp_apply (wp_wand with "(He [HΓ //])"); iIntros (w) "[HB $]". by iExists M. wp_apply (wp_wand with "(He [HΓ //])"); iIntros (w) "[HB $]". by iExists M.
Qed. Qed.
Lemma ltyped_unpack {k} Γ1 Γ2 Γ3 x e1 e2 (C : lty Σ k ltty Σ) B : (* TODO(TYRULES) *)
(Γ1 e1 : lty_exist C Γ2) - (* NOTE: This only works when `x` is a string, not when it is a (more general)
( Y, binder_insert x (C Y) Γ2 e2 : B Γ3) - binder. This means that it doesn't work for anonymous binders, but there
Γ1 (let: x := e1 in e2) : B binder_delete x Γ3. really isn't any reason to unpack those anyway. *)
Lemma ltyped_unpack {k} Γ1 Γ2 Γ3 (x : string) e (C : lty Σ k ltty Σ) A :
Γ1 !! x = Some (lty_exist C)
( X, binder_insert x (C X) Γ1 e : A Γ2) -
(Γ1 e : A Γ2).
Proof. Proof.
iIntros "#He1 #He2 !>". iIntros (vs) "HΓ1"=> /=. (* iIntros "#He1 #He2 !>". iIntros (vs) "HΓ1"=> /=. *)
wp_apply (wp_wand with "(He1 HΓ1)"). (* wp_apply (wp_wand with "(He1 HΓ1)"). *)
iIntros (v) "[HC HΓ2]". (* iIntros (v) "[HC HΓ2]". *)
iDestruct "HC" as (X) "HX". (* iDestruct "HC" as (X) "HX". *)
wp_pures. (* wp_pures. *)
iDestruct (env_ltyped_insert _ _ x with "HX HΓ2") as "HΓ2". (* iDestruct (env_ltyped_insert _ _ x with "HX HΓ2") as "HΓ2". *)
iDestruct ("He2" with "HΓ2") as "He2'". (* iDestruct ("He2" with "HΓ2") as "He2'". *)
destruct x as [|x]; rewrite /= -?subst_map_insert //. (* destruct x as [|x]; rewrite /= -?subst_map_insert //. *)
wp_apply (wp_wand with "He2'"). (* wp_apply (wp_wand with "He2'"). *)
iIntros (w) "[HA2 HΓ3]". (* iIntros (w) "[HA2 HΓ3]". *)
iFrame. (* iFrame. *)
iApply env_ltyped_delete=> //. (* iApply env_ltyped_delete=> //. *)
Qed. Admitted.
(** Mutable Reference properties *) (** Mutable Reference properties *)
Definition alloc : val := λ: "init", ref "init". (* TODO(TYRULES) *)
Lemma ltyped_alloc A : Lemma ltyped_alloc Γ1 Γ2 e A :
alloc : A ref_mut A. (Γ1 e : A Γ2) -
(Γ1 ref e : ref_mut A Γ2).
Proof. Proof.
iIntros (vs) "!> HΓ /=". iApply wp_value. (* iIntros (vs) "!> HΓ /=". iApply wp_value. *)
iSplitL; last by iApply env_ltyped_empty. (* iSplitL; last by iApply env_ltyped_empty. *)
iIntros "!>" (v) "Hv". rewrite /alloc. wp_pures. (* iIntros "!>" (v) "Hv". rewrite /alloc. wp_pures. *)
wp_alloc l as "Hl". (* wp_alloc l as "Hl". *)
iExists l, v. iSplit=> //. (* iExists l, v. iSplit=> //. *)
iFrame "Hv Hl". (* iFrame "Hv Hl". *)
Qed. Admitted.
(* The intuition for the any is that the value is still there, but (* The intuition for the any is that the value is still there, but
it no longer holds any Iris resources. Just as in Rust, where a move it no longer holds any Iris resources. Just as in Rust, where a move
...@@ -280,45 +284,32 @@ Section properties. ...@@ -280,45 +284,32 @@ Section properties.
unmodified, but moves the resources, in the sense that you can no unmodified, but moves the resources, in the sense that you can no
longer use the memory at the old location. *) longer use the memory at the old location. *)
Definition load : val := λ: "r", (!"r", "r"). Definition load : val := λ: "r", (!"r", "r").
Lemma ltyped_load A : Lemma ltyped_load Γ (x : string) A :
load : ref_mut A A * ref_mut any. Γ !! x = Some (ref_mut A)%lty
Γ ! x : A <[x := (ref_mut (copy- A))%lty]> Γ.
Proof. Proof.
iIntros (vs) "!> HΓ /=". iApply wp_value. (* iIntros (vs) "!> HΓ /=". iApply wp_value. *)
iSplitL; last by iApply env_ltyped_empty. (* iSplitL; last by iApply env_ltyped_empty. *)
iIntros "!>" (v) "Hv". rewrite /load. wp_pures. (* iIntros "!>" (v) "Hv". rewrite /load. wp_pures. *)
iDestruct "Hv" as (l w ->) "[Hl Hw]". (* iDestruct "Hv" as (l w ->) "[Hl Hw]". *)
wp_load. wp_pures. (* wp_load. wp_pures. *)
iExists w, #l. iSplit=> //. iFrame "Hw". (* iExists w, #l. iSplit=> //. iFrame "Hw". *)
iExists l, w. iSplit=> //. iFrame "Hl". (* iExists l, w. iSplit=> //. iFrame "Hl". *)
by iModIntro. (* by iModIntro. *)
Qed. Admitted.
(* TODO(COPY) *) Lemma ltyped_store Γ Γ' x e1 e2 A B :
(* Lemma ltyped_load_copy A {copyA : LTyCopy A} : *) Γ' !! x = Some (ref_mut A)%lty
(* ⊢ ∅ ⊨ load : ref_mut A → A * ref_mut A. *) (Γ e2 : B Γ') -
(* Proof. *) Γ e1 <- e2 : () <[x := (ref_mut B)%lty]> Γ'.
(* iIntros (vs) "!> HΓ /=". *)
(* iApply wp_value. *)
(* iIntros "!>" (v) "Hv". rewrite /load. wp_pures. *)
(* iDestruct "Hv" as (l w ->) "[Hl #Hw]". *)
(* wp_load. wp_pures. *)
(* iExists w, #l. iSplit=> //. iFrame "Hw". *)
(* iExists l, w. iSplit=> //. iFrame "Hl". *)
(* by iModIntro. *)
(* Qed. *)
Definition store : val := λ: "r" "new", "r" <- "new";; "r".
Lemma ltyped_store A B :
store : ref_mut A B ref_mut B.
Proof. Proof.
iIntros (vs) "!> HΓ /=". iApply wp_value. (* iIntros (vs) "!> HΓ /=". iApply wp_value. *)
iSplitL; last by iApply env_ltyped_empty. (* iSplitL; last by iApply env_ltyped_empty. *)
iIntros "!>" (v) "Hv". rewrite /store. wp_pures. (* iIntros "!>" (v) "Hv". rewrite /store. wp_pures. *)
iDestruct "Hv" as (l old ->) "[Hl Hold]". (* iDestruct "Hv" as (l old ->) "[Hl Hold]". *)
iIntros (new) "Hnew". wp_store. (* iIntros (new) "Hnew". wp_store. *)
iExists l, new. eauto with iFrame. (* iExists l, new. eauto with iFrame. *)
Qed. Admitted.
(** Weak Reference properties *) (** Weak Reference properties *)
Definition fetch_and_add : val := λ: "r" "inc", FAA "r" "inc". Definition fetch_and_add : val := λ: "r" "inc", FAA "r" "inc".
......
Markdown is supported
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