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

type new and delete in new type system

parent 77b0063a
No related branches found
No related tags found
No related merge requests found
Pipeline #
...@@ -6,13 +6,13 @@ Definition new : val := ...@@ -6,13 +6,13 @@ Definition new : val :=
λ: ["n"], λ: ["n"],
if: "n" #0 then #((42%positive, 1337):loc) if: "n" #0 then #((42%positive, 1337):loc)
else Alloc "n". else Alloc "n".
Opaque new. Global Opaque new.
Definition delete : val := Definition delete : val :=
λ: ["n"; "loc"], λ: ["n"; "loc"],
if: "n" #0 then #() if: "n" #0 then #()
else Free "n" "loc". else Free "n" "loc".
Opaque delete. Global Opaque delete.
Section specs. Section specs.
Context `{heapG Σ}. Context `{heapG Σ}.
......
...@@ -4,7 +4,7 @@ From iris.base_logic Require Import big_op. ...@@ -4,7 +4,7 @@ From iris.base_logic Require Import big_op.
From lrust.lifetime Require Import borrow frac_borrow. From lrust.lifetime Require Import borrow frac_borrow.
From lrust.lang Require Export new_delete. From lrust.lang Require Export new_delete.
From lrust.typing Require Export type. From lrust.typing Require Export type.
From lrust.typing Require Import uninit type_context programs perm typing. From lrust.typing Require Import uninit type_context programs.
Section own. Section own.
Context `{typeG Σ}. Context `{typeG Σ}.
...@@ -171,34 +171,32 @@ Section typing. ...@@ -171,34 +171,32 @@ Section typing.
iFrame. iApply uninit_own. auto. iFrame. iApply uninit_own. auto.
Qed. Qed.
(* Old Typing *) Lemma type_new E L (n : nat) :
Lemma typed_new ρ (n : nat): typed_instruction_ty E L [] (new [ #n ]%E) (own n (uninit n)).
0 n typed_step_ty ρ (new [ #n]%E) (own n (uninit n)).
Proof. Proof.
iIntros (Hn tid) "!#(#HEAP&_&_&$)". iApply (wp_new with "HEAP"); try done. iIntros (tid eq) "#HEAP #LFT $ $ $ _".
iIntros "!>*(% & H† & H↦)". iExists _. iSplit. done. iNext. iApply (wp_new with "HEAP"); try done; first omega. iModIntro.
rewrite Nat2Z.id. iSplitR "H†". iIntros (l vl) "(% & H† & Hlft)". rewrite tctx_interp_singleton tctx_hasty_val.
iExists _. iSplit; first done. iNext. rewrite Nat2Z.id. iSplitR "H†".
- iExists vl. iFrame. - iExists vl. iFrame.
match goal with H : Z.of_nat n = Z.of_nat (length vl) |- _ => rename H into Hlen end. match goal with H : Z.of_nat n = Z.of_nat (length vl) |- _ => rename H into Hlen end.
clear Hn. apply (inj Z.of_nat) in Hlen. subst. apply (inj Z.of_nat) in Hlen. subst.
iInduction vl as [|v vl] "IH". done. iInduction vl as [|v vl] "IH". done.
iExists [v], vl. iSplit. done. by iSplit. iExists [v], vl. iSplit. done. by iSplit.
- by rewrite uninit_sz freeable_sz_full. - by rewrite uninit_sz freeable_sz_full.
Qed. Qed.
Lemma type_delete E L n ty p :
Lemma typed_delete ty (ν : expr): n = ty.(ty_size)
typed_step (ν own ty.(ty_size) ty) (delete [ #ty.(ty_size); ν])%E (λ _, top). typed_instruction E L [TCtx_hasty p (own n ty)] (delete [ #n; p])%E (λ _, []).
Proof. Proof.
iIntros (tid) "!#(#HEAP&_&H◁&$)". wp_bind ν. iIntros (-> tid eq) "#HEAP #LFT $ $ $ Hp". rewrite tctx_interp_singleton.
iApply (has_type_wp with "[$H◁]"). iIntros (v) "_ H◁ !>". wp_bind p. iApply (wp_hasty with "Hp"). iIntros (v) "_ Hown".
rewrite has_type_value. iDestruct "Hown" as (l) "(Hv & H↦∗: & >H†)". iDestruct "Hv" as %[=->].
iDestruct "H◁" as (l) "(Hv & H↦∗: & >H†)". iDestruct "Hv" as %[=->]. iDestruct "H↦∗:" as (vl) "[>H↦ Hown]". rewrite tctx_interp_nil.
iDestruct "H↦∗:" as (vl) "[>H↦ Hown]".
rewrite ty_size_eq. iDestruct "Hown" as ">Hown". iDestruct "Hown" as %<-. rewrite ty_size_eq. iDestruct "Hown" as ">Hown". iDestruct "Hown" as %<-.
iApply (wp_delete with "[-]"); try by auto. iApply (wp_delete with "[-]"); try (by auto); [].
rewrite freeable_sz_full. by iFrame. rewrite freeable_sz_full. by iFrame.
Qed. Qed.
End typing. End typing.
...@@ -3,7 +3,7 @@ From iris.base_logic Require Import big_op. ...@@ -3,7 +3,7 @@ From iris.base_logic Require Import big_op.
From lrust.lifetime Require Import borrow frac_borrow reborrow. From lrust.lifetime Require Import borrow frac_borrow reborrow.
From lrust.lang Require Import heap. From lrust.lang Require Import heap.
From lrust.typing Require Export type. From lrust.typing Require Export type.
From lrust.typing Require Import lft_contexts type_context shr_bor perm typing programs. From lrust.typing Require Import lft_contexts type_context shr_bor programs.
Section uniq_bor. Section uniq_bor.
Context `{typeG Σ}. Context `{typeG Σ}.
......
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