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

change notation for memcpy. notation for sum injection has a \Sigma.

parent 427363dc
No related branches found
No related tags found
No related merge requests found
...@@ -10,22 +10,22 @@ Definition memcpy : val := ...@@ -10,22 +10,22 @@ Definition memcpy : val :=
"memcpy" ["dst" + #1 ; "len" - #1 ; "src" + #1]. "memcpy" ["dst" + #1 ; "len" - #1 ; "src" + #1].
Global Opaque memcpy. Global Opaque memcpy.
Notation "e1 <⋯ !{ n } e2" := Notation "e1 <-{ n } ! e2" :=
(memcpy (@cons expr e1%E (memcpy (@cons expr e1%E
(@cons expr (Lit n) (@cons expr (Lit n)
(@cons expr e2%E nil)))) (@cons expr e2%E nil))))
(at level 80, n at next level, format "e1 <⋯ !{ n } e2") : expr_scope. (at level 80, n at next level, format "e1 <-{ n } ! e2") : expr_scope.
Notation "e1 <{ i } !{ n } e2" := Notation "e1 <-{ n ',Σ' i } ! e2" :=
(e1 <-{i} ;; e1+#1 < !{n}e2)%E (e1 <-{Σ i} () ;; e1+#1 <-{n} !e2)%E
(at level 80, n, i at next level, (at level 80, n, i at next level,
format "e1 <{ i } !{ n } e2") : expr_scope. format "e1 <-{ n ,Σ i } ! e2") : expr_scope.
Lemma wp_memcpy `{heapG Σ} E l1 l2 vl1 vl2 q n: Lemma wp_memcpy `{heapG Σ} E l1 l2 vl1 vl2 q n:
heapN E heapN E
length vl1 = n length vl2 = n length vl1 = n length vl2 = n
{{{ heap_ctx l1 ↦∗ vl1 l2 ↦∗{q} vl2 }}} {{{ heap_ctx l1 ↦∗ vl1 l2 ↦∗{q} vl2 }}}
#l1 < !{n}#l2 @ E #l1 <-{n} !#l2 @ E
{{{ RET #(); l1 ↦∗ vl2 l2 ↦∗{q} vl2 }}}. {{{ RET #(); l1 ↦∗ vl2 l2 ↦∗{q} vl2 }}}.
Proof. Proof.
iIntros (? Hvl1 Hvl2 Φ) "(#Hinv & Hl1 & Hl2) HΦ". iIntros (? Hvl1 Hvl2 Φ) "(#Hinv & Hl1 & Hl2) HΦ".
......
...@@ -45,6 +45,6 @@ End specs. ...@@ -45,6 +45,6 @@ End specs.
Notation "'letalloc:' x <- e1 'in' e2" := Notation "'letalloc:' x <- e1 'in' e2" :=
((Lam (@cons binder x%E%E%E nil) (x <- e1 ;; e2)) [new [ #1]])%E ((Lam (@cons binder x%E%E%E nil) (x <- e1 ;; e2)) [new [ #1]])%E
(at level 102, x at level 1, e1, e2 at level 200) : expr_scope. (at level 102, x at level 1, e1, e2 at level 200) : expr_scope.
Notation "'letalloc:' x <⋯ !{ n } e1 'in' e2" := Notation "'letalloc:' x <-{ n } ! e1 'in' e2" :=
((Lam (@cons binder x%E%E%E nil) (x < !{n%Z%V}e1 ;; e2)) [new [ #n]])%E ((Lam (@cons binder x%E%E%E nil) (x <-{n%Z%V} !e1 ;; e2)) [new [ #n]])%E
(at level 102, x at level 1, e1, e2 at level 200) : expr_scope. (at level 102, x at level 1, e1, e2 at level 200) : expr_scope.
...@@ -85,7 +85,10 @@ Notation "'letcall:' x := f args 'in' e" := ...@@ -85,7 +85,10 @@ Notation "'letcall:' x := f args 'in' e" :=
(call: f args "_k" cont: "_k" [ x ] := e)%E (call: f args "_k" cont: "_k" [ x ] := e)%E
(at level 102, x, f, args at level 1, e at level 150) : expr_scope. (at level 102, x, f, args at level 1, e at level 150) : expr_scope.
Notation "e1 <-{ i } '☇'" := (e1 <- #i)%E (* RJ: These notations unfortunately do not print. Also, I don't think
(only parsing, at level 80) : expr_scope. we would even want them to print in general.
Notation "e1 <-{ i } e2" := (e1 <-{i} ;; e1+#1 <- e2)%E TODO: Introduce a Definition. *)
(at level 80) : expr_scope. Notation "e1 '<-{Σ' i } '()'" := (e1 <- #i)%E
(only parsing, at level 80, format "e1 <-{Σ i } ()" ) : expr_scope.
Notation "e1 '<-{Σ' i } e2" := (e1 <-{Σ i} () ;; e1+#1 <- e2)%E
(at level 80, format "e1 <-{Σ i } e2") : expr_scope.
...@@ -274,15 +274,15 @@ Section typing. ...@@ -274,15 +274,15 @@ Section typing.
tctx_extract_hasty E L p ty1 T T' tctx_extract_hasty E L p ty1 T T'
( (v : val), ( (v : val),
typed_body E L C ((v own_ptr (ty.(ty_size)) ty)::(p ty2)::T') (subst x v e)) typed_body E L C ((v own_ptr (ty.(ty_size)) ty)::(p ty2)::T') (subst x v e))
typed_body E L C T (letalloc: x < !{ty.(ty_size)}p in e). typed_body E L C T (letalloc: x <-{ty.(ty_size)} !p in e).
Proof. Proof.
intros. eapply type_new. intros. eapply type_new.
- rewrite /Closed /=. rewrite !andb_True. - rewrite /Closed /=. rewrite !andb_True.
eauto 100 using is_closed_weaken with set_solver. eauto 100 using is_closed_weaken with set_solver.
- lia. - lia.
- move=>xv /=. - move=>xv /=.
assert (subst x xv (x < !{ty.(ty_size)}p ;; e)%E = assert (subst x xv (x <-{ty.(ty_size)} !p ;; e)%E =
(xv < !{ty.(ty_size)}p ;; subst x xv e)%E) as ->. (xv <-{ty.(ty_size)} !p ;; subst x xv e)%E) as ->.
{ (* TODO : simpl_subst should be able to do this. *) { (* TODO : simpl_subst should be able to do this. *)
unfold subst=>/=. repeat f_equal. unfold subst=>/=. repeat f_equal.
- eapply (is_closed_subst []). done. set_solver. - eapply (is_closed_subst []). done. set_solver.
...@@ -306,4 +306,4 @@ Hint Resolve own_mono' own_proper' : lrust_typing. ...@@ -306,4 +306,4 @@ Hint Resolve own_mono' own_proper' : lrust_typing.
Hint Extern 100 (_ _) => simpl; lia : lrust_typing. Hint Extern 100 (_ _) => simpl; lia : lrust_typing.
Hint Extern 100 (@eq Z _ _) => simpl; lia : lrust_typing. Hint Extern 100 (@eq Z _ _) => simpl; lia : lrust_typing.
Hint Extern 100 (@eq nat _ _) => simpl; lia : lrust_typing. Hint Extern 100 (@eq nat _ _) => simpl; lia : lrust_typing.
\ No newline at end of file
...@@ -234,7 +234,7 @@ Section typing_rules. ...@@ -234,7 +234,7 @@ Section typing_rules.
typed_write E L ty1 ty ty1' -∗ typed_read E L ty2 ty ty2' -∗ typed_write E L ty1 ty ty1' -∗ typed_read E L ty2 ty ty2' -∗
{{{ heap_ctx lft_ctx na_own tid elctx_interp E qE llctx_interp L qL {{{ heap_ctx lft_ctx na_own tid elctx_interp E qE llctx_interp L qL
tctx_elt_interp tid (p1 ty1) tctx_elt_interp tid (p2 ty2) }}} tctx_elt_interp tid (p1 ty1) tctx_elt_interp tid (p2 ty2) }}}
(p1 < !{n}p2) (p1 <-{n} !p2)
{{{ RET #(); na_own tid elctx_interp E qE llctx_interp L qL {{{ RET #(); na_own tid elctx_interp E qE llctx_interp L qL
tctx_elt_interp tid (p1 ty1') tctx_elt_interp tid (p2 ty2') }}}. tctx_elt_interp tid (p1 ty1') tctx_elt_interp tid (p2 ty2') }}}.
Proof. Proof.
...@@ -257,7 +257,7 @@ Section typing_rules. ...@@ -257,7 +257,7 @@ Section typing_rules.
Lemma type_memcpy_instr {E L} ty ty1 ty1' ty2 ty2' (n : Z) p1 p2 : Lemma type_memcpy_instr {E L} ty ty1 ty1' ty2 ty2' (n : Z) p1 p2 :
Z.of_nat (ty.(ty_size)) = n Z.of_nat (ty.(ty_size)) = n
typed_write E L ty1 ty ty1' typed_read E L ty2 ty ty2' typed_write E L ty1 ty ty1' typed_read E L ty2 ty ty2'
typed_instruction E L [p1 ty1; p2 ty2] (p1 < !{n}p2) typed_instruction E L [p1 ty1; p2 ty2] (p1 <-{n} !p2)
(λ _, [p1 ty1'; p2 ty2']%TC). (λ _, [p1 ty1'; p2 ty2']%TC).
Proof. Proof.
iIntros (Hsz Hwrt Hread) "!#". iIntros (tid qE) "#HEAP #LFT Htl HE HL HT". iIntros (Hsz Hwrt Hread) "!#". iIntros (tid qE) "#HEAP #LFT Htl HE HL HT".
...@@ -276,7 +276,7 @@ Section typing_rules. ...@@ -276,7 +276,7 @@ Section typing_rules.
typed_read E L ty2 ty ty2' typed_read E L ty2 ty ty2'
Z.of_nat (ty.(ty_size)) = n Z.of_nat (ty.(ty_size)) = n
typed_body E L C ((p1 ty1') :: (p2 ty2') :: T') e typed_body E L C ((p1 ty1') :: (p2 ty2') :: T') e
typed_body E L C T (p1 < !{n}p2;; e). typed_body E L C T (p1 <-{n} !p2;; e).
Proof. Proof.
intros. by eapply type_seq; [|by eapply (type_memcpy_instr ty ty1 ty1')|..]. intros. by eapply type_seq; [|by eapply (type_memcpy_instr ty ty1 ty1')|..].
Qed. Qed.
......
...@@ -7,8 +7,8 @@ Section option_as_mut. ...@@ -7,8 +7,8 @@ Section option_as_mut.
Definition option_as_mut : val := Definition option_as_mut : val :=
funrec: <> ["o"] := funrec: <> ["o"] :=
let: "o'" := !"o" in case: !"o'" of let: "o'" := !"o" in case: !"o'" of
[ let: "r" := new [ #2 ] in "r" <-{0} ;; "k" ["r"]; [ let: "r" := new [ #2 ] in "r" <-{Σ 0} ();; "k" ["r"];
let: "r" := new [ #2 ] in "r" <-{1} "o'" + #1;; "k" ["r"] ] let: "r" := new [ #2 ] in "r" <-{Σ 1} "o'" + #1;; "k" ["r"] ]
cont: "k" ["r"] := cont: "k" ["r"] :=
delete [ #1; "o"];; "return" ["r"]. delete [ #1; "o"];; "return" ["r"].
......
...@@ -8,7 +8,7 @@ Section unwrap_or. ...@@ -8,7 +8,7 @@ Section unwrap_or.
funrec: <> ["o"; "def"] := funrec: <> ["o"; "def"] :=
case: !"o" of case: !"o" of
[ delete [ #(S τ.(ty_size)); "o"];; "return" ["def"]; [ delete [ #(S τ.(ty_size)); "o"];; "return" ["def"];
letalloc: "r" < !{τ.(ty_size)}("o" + #1) in letalloc: "r" <-{τ.(ty_size)} !("o" + #1) in
delete [ #(S τ.(ty_size)); "o"];; delete [ #τ.(ty_size); "def"];; "return" ["r"]]. delete [ #(S τ.(ty_size)); "o"];; delete [ #τ.(ty_size); "def"];; "return" ["r"]].
Lemma unwrap_or_type τ : Lemma unwrap_or_type τ :
......
...@@ -154,7 +154,7 @@ Section case. ...@@ -154,7 +154,7 @@ Section case.
Lemma type_sum_assign_instr {E L} (i : nat) ty1 tyl ty ty2 p1 p2 : Lemma type_sum_assign_instr {E L} (i : nat) ty1 tyl ty ty2 p1 p2 :
typed_write E L ty1 (sum tyl) ty2 typed_write E L ty1 (sum tyl) ty2
tyl !! i = Some ty tyl !! i = Some ty
typed_instruction E L [p1 ty1; p2 ty] (p1 <-{i} p2) (λ _, [p1 ty2]%TC). typed_instruction E L [p1 ty1; p2 ty] (p1 <-{Σ i} p2) (λ _, [p1 ty2]%TC).
Proof. Proof.
iIntros (Hw Hty) "!# * #HEAP #LFT $ HE HL Hp". iIntros (Hw Hty) "!# * #HEAP #LFT $ HE HL Hp".
rewrite tctx_interp_cons tctx_interp_singleton. rewrite tctx_interp_cons tctx_interp_singleton.
...@@ -185,7 +185,7 @@ Section case. ...@@ -185,7 +185,7 @@ Section case.
typed_write E L ty1 (sum tyl) ty1' typed_write E L ty1 (sum tyl) ty1'
tyl !! (Z.to_nat i) = Some ty tyl !! (Z.to_nat i) = Some ty
typed_body E L C ((p1 ty1') :: T') e typed_body E L C ((p1 ty1') :: T') e
typed_body E L C T (p1 <-{i} p2 ;; e). typed_body E L C T (p1 <-{Σ i} p2 ;; e).
Proof. Proof.
intros. rewrite -(Z2Nat.id i) //. intros. rewrite -(Z2Nat.id i) //.
eapply type_seq; [done|by eapply type_sum_assign_instr|done|done]. eapply type_seq; [done|by eapply type_sum_assign_instr|done|done].
...@@ -194,7 +194,7 @@ Section case. ...@@ -194,7 +194,7 @@ Section case.
Lemma type_sum_assign_unit_instr {E L} (i : nat) tyl ty1 ty2 p : Lemma type_sum_assign_unit_instr {E L} (i : nat) tyl ty1 ty2 p :
tyl !! i = Some unit tyl !! i = Some unit
typed_write E L ty1 (sum tyl) ty2 typed_write E L ty1 (sum tyl) ty2
typed_instruction E L [p ty1] (p <-{i} ) (λ _, [p ty2]%TC). typed_instruction E L [p ty1] (p <-{Σ i} ()) (λ _, [p ty2]%TC).
Proof. Proof.
iIntros (Hty Hw) "!# * #HEAP #LFT $ HE HL Hp". rewrite tctx_interp_singleton. iIntros (Hty Hw) "!# * #HEAP #LFT $ HE HL Hp". rewrite tctx_interp_singleton.
wp_bind p. iApply (wp_hasty with "Hp"). iIntros (v Hv) "Hty". wp_bind p. iApply (wp_hasty with "Hp"). iIntros (v Hv) "Hty".
...@@ -213,7 +213,7 @@ Section case. ...@@ -213,7 +213,7 @@ Section case.
typed_write E L ty1 (sum tyl) ty1' typed_write E L ty1 (sum tyl) ty1'
tyl !! (Z.to_nat i) = Some unit tyl !! (Z.to_nat i) = Some unit
typed_body E L C ((p ty1') :: T') e typed_body E L C ((p ty1') :: T') e
typed_body E L C T (p <-{i} ;; e). typed_body E L C T (p <-{Σ i} () ;; e).
Proof. Proof.
intros. rewrite -(Z2Nat.id i) //. intros. rewrite -(Z2Nat.id i) //.
eapply type_seq; [done|by eapply type_sum_assign_unit_instr|solve_typing|done]. eapply type_seq; [done|by eapply type_sum_assign_unit_instr|solve_typing|done].
...@@ -224,7 +224,7 @@ Section case. ...@@ -224,7 +224,7 @@ Section case.
typed_write E L ty1 (sum tyl) ty1' typed_write E L ty1 (sum tyl) ty1'
typed_read E L ty2 ty ty2' typed_read E L ty2 ty ty2'
typed_instruction E L [p1 ty1; p2 ty2] typed_instruction E L [p1 ty1; p2 ty2]
(p1 <{i} !{ty.(ty_size)}p2) (λ _, [p1 ty1'; p2 ty2']%TC). (p1 <-{ty.(ty_size),Σ i} !p2) (λ _, [p1 ty1'; p2 ty2']%TC).
Proof. Proof.
iIntros (Hty Hw Hr) "!# * #HEAP #LFT Htl [HE1 HE2] [HL1 HL2] Hp". iIntros (Hty Hw Hr) "!# * #HEAP #LFT Htl [HE1 HE2] [HL1 HL2] Hp".
rewrite tctx_interp_cons tctx_interp_singleton. rewrite tctx_interp_cons tctx_interp_singleton.
...@@ -266,7 +266,7 @@ Section case. ...@@ -266,7 +266,7 @@ Section case.
Z.of_nat (ty.(ty_size)) = n Z.of_nat (ty.(ty_size)) = n
tyl !! (Z.to_nat i) = Some ty tyl !! (Z.to_nat i) = Some ty
typed_body E L C ((p1 ty1') :: (p2 ty2') :: T') e typed_body E L C ((p1 ty1') :: (p2 ty2') :: T') e
typed_body E L C T (p1 <{i} !{n}p2 ;; e). typed_body E L C T (p1 <-{n,Σ i} !p2 ;; e).
Proof. Proof.
intros ???? Hr ???. subst. rewrite -(Z2Nat.id i) //. intros ???? Hr ???. subst. rewrite -(Z2Nat.id i) //.
by eapply type_seq; [done|eapply type_sum_memcpy_instr, Hr|done|done]. by eapply type_seq; [done|eapply type_sum_memcpy_instr, Hr|done|done].
......
...@@ -81,7 +81,7 @@ Section typing. ...@@ -81,7 +81,7 @@ Section typing.
Definition cell_write ty : val := Definition cell_write ty : val :=
funrec: <> ["c"; "x"] := funrec: <> ["c"; "x"] :=
let: "c'" := !"c" in let: "c'" := !"c" in
"c'" < !{ty.(ty_size)} "x";; "c'" <-{ty.(ty_size)} !"x";;
let: "r" := new [ #0 ] in let: "r" := new [ #0 ] in
delete [ #1; "c"] ;; delete [ #ty.(ty_size); "x"] ;; "return" ["r"]. delete [ #1; "c"] ;; delete [ #ty.(ty_size); "x"] ;; "return" ["r"].
......
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