diff --git a/_CoqProject b/_CoqProject index 2c80f2f780c15ea78534f3e42fc0038770c38314..bdae70842e99ef223c076c4c1b33b2c603763ce4 100644 --- a/_CoqProject +++ b/_CoqProject @@ -46,3 +46,4 @@ theories/typing/type_sum.v theories/typing/tests/get_x.v theories/typing/tests/rebor.v theories/typing/tests/unbox.v +theories/typing/tests/init_prod.v diff --git a/theories/typing/own.v b/theories/typing/own.v index 22a3cd2726f213b7bdf2e8ea30e4b4de91bcbb8a..8ce49d9decdbc7e27dede7799435a317cc2a49a9 100644 --- a/theories/typing/own.v +++ b/theories/typing/own.v @@ -210,6 +210,21 @@ Section typing. typed_body E L C T (let: x := new [ #n ] in e). Proof. intros. eapply type_let. done. by apply type_new_instr. solve_typing. done. Qed. + Lemma type_new_subtype ty E L C T x (n : Z) e : + Closed (x :b: []) e → + 0 ≤ n → + let n' := Z.to_nat n in + subtype E L (uninit n') ty → + (∀ (v : val), typed_body E L C ((v ◠own n' ty) :: T) (subst' x v e)) → + typed_body E L C T (let: x := new [ #n ] in e). + Proof. + intros ???? Htyp. eapply type_let. done. by apply type_new_instr. solve_typing. + iIntros (v). iApply typed_body_mono; [done| |done|]. + (* FIXME : why can't we iApply Htyp? *) + 2:by iDestruct (Htyp v) as "$". + by apply (tctx_incl_frame_r _ [_] [_]), subtype_tctx_incl, own_mono. + Qed. + Lemma type_delete_instr {E L} ty (n : Z) p : Z.of_nat (ty.(ty_size)) = n → typed_instruction E L [p ◠own (ty.(ty_size)) ty] (delete [ #n; p])%E (λ _, []). diff --git a/theories/typing/product_split.v b/theories/typing/product_split.v index e5a4a798016f8559da2edda457347c691e4945ef..a6a3262f20b4f184cdc3b971f60efe8d0a4c331b 100644 --- a/theories/typing/product_split.v +++ b/theories/typing/product_split.v @@ -401,4 +401,6 @@ Hint Extern 0 (tctx_extract_hasty _ _ _ _ (hasty_ptr_offsets _ _ _ _) _) => cbn[hasty_ptr_offsets]. +Hint Extern 0 (tctx_extract_hasty _ _ _ _ (_ ++ _) _) => cbn[app]. + Hint Unfold extract_tyl : lrust_typing. diff --git a/theories/typing/tests/init_prod.v b/theories/typing/tests/init_prod.v new file mode 100644 index 0000000000000000000000000000000000000000..fd2a718996f309cf202f86869fbefa8de3b3e958 --- /dev/null +++ b/theories/typing/tests/init_prod.v @@ -0,0 +1,34 @@ +From lrust.lifetime Require Import definitions. +From lrust.lang Require Import new_delete. +From lrust.typing Require Import programs product product_split own uniq_bor + shr_bor int function lft_contexts uninit cont borrow. +Set Default Proof Using "Type". + +Section rebor. + Context `{typeG Σ}. + + Definition init_prod := + (funrec: <> ["x"; "y"] := + let: "x'" := !"x" in let: "y'" := !"y" in + let: "r" := new [ #2] in + "r" +ₗ #0 <- "x'";; "r" +ₗ #1 <- "y'";; + delete [ #1; "x"] ;; delete [ #1; "y"] ;; "return" ["r":expr])%E. + + Lemma init_prod_type : + typed_instruction_ty [] [] [] init_prod + (fn (λ _, []) (λ _, [# own 1 int; own 1 int]) + (λ (_ : ()), own 2 (Π[int;int]))). + Proof. + apply type_fn; try apply _. move=> /= [] ret p. inv_vec p=>x y. simpl_subst. + eapply type_deref; try solve_typing; [apply read_own_move|done|]=>x'. simpl_subst. + eapply type_deref; try solve_typing; [apply read_own_move|done|]=>y'. simpl_subst. + eapply (type_new_subtype (Π[uninit 1; uninit 1])); [apply _|done| |]. + { apply (uninit_product_subtype [] [] [1;1]%nat). } + intros r. simpl_subst. unfold Z.to_nat, Pos.to_nat; simpl. + eapply (type_assign (own 2 (uninit 1))); try solve_typing. by apply write_own. + eapply (type_assign (own 2 (uninit 1))); try solve_typing. by apply write_own. + eapply type_delete; try solve_typing. + eapply type_delete; try solve_typing. + eapply (type_jump [_]); solve_typing. + Qed. +End rebor.