RustBelt試è¡ä¸: get_x ã®ä¸è¬å
RustBeltã® examples/get_x.v
ãããã£ã¦ã¿ãã
From iris.proofmode Require Import tactics. From lrust.typing Require Import typing. Set Default Proof Using "Type". Section get_x. Context `{typeG Σ}. Definition get_x : val := funrec: <> ["p"] := let: "p'" := !"p" in letalloc: "r" <- "p'" +â #0 in delete [ #1; "p"] ;; return: ["r"]. Lemma get_x_type : typed_val get_x (fn(â α, â ; &uniq{α} Î [int; int]) â &shr{α} int). Proof. intros E L. iApply type_fn; [solve_typing..|]. iIntros "/= !#". iIntros (α Ï ret p). inv_vec p=>p. simpl_subst. iApply type_deref; [solve_typing..|]. iIntros (p'); simpl_subst. iApply (type_letalloc_1 (&shr{α}int)); [solve_typing..|]. iIntros (r). simpl_subst. iApply type_delete; [solve_typing..|]. iApply type_jump; solve_typing. Qed. End get_x.
ããã¯ã ããã以ä¸ã®ãããªããã°ã©ã ã表ãã¦ããããã ã
fn get_x<'a>(p: &'a mut (i32, i32)) -> &'a i32 { &p.0 }
ãã ããç¾å¨ã®Î»Rustã§ã¯æ´æ°åã¯ã²ã¨ã¤ãããªããç¡éã«å¤§ããªæ´æ°ãä¿æå¯è½ã§ããµã¤ãºã¯1ã§ãã (ãã¤ã³ã¿ã®ãµã¤ãºã1)ã
ããã
fn fst<'a, T, U>(p: &'a mut (T, U)) -> &'a T { &p.0 }
ã«ä¸è¬åãã¦ã¿ãã試è¡é¯èª¤ã®çµæã以ä¸ã®ããã«ããã¨ä¸æããããã¨ãããã£ãã
From iris.proofmode Require Import tactics. From lrust.typing Require Import typing. Set Default Proof Using "Type". Section get_x. Context `{typeG Σ}. Definition get_x T U `{!TyWf T} `{!TyWf U} : val := funrec: <> ["p"] := let: "p'" := !"p" in letalloc: "r" <- "p'" +â #0 in delete [ #1; "p"] ;; return: ["r"]. Lemma get_x_type T U `{!TyWf T} `{!TyWf U} : typed_val (get_x T U) (fn(â α, â ; &uniq{α} Î [T; U]) â &shr{α} T). Proof. intros E L. iApply type_fn; [solve_typing..|]. iIntros "/= !#". iIntros (α Ï ret p). inv_vec p=>p. simpl_subst. iApply type_deref; [solve_typing..|]. iIntros (p'); simpl_subst. iApply (type_letalloc_1 (&shr{α}T)); [solve_typing..|]. iIntros (r). simpl_subst. iApply type_delete; [solve_typing..|]. iApply type_jump; solve_typing. Qed. End get_x.
åæ§ã«ã
fn snd<'a, T, U>(p: &'a mut (T, U)) -> &'a U { &p.1 }
ã¯ä»¥ä¸ã®ããã«å®ç¾©ã§ããã
From iris.proofmode Require Import tactics. From lrust.typing Require Import typing. Set Default Proof Using "Type". Section snd. Context `{typeG Σ}. Definition snd T U `{!TyWf T} `{!TyWf U} : val := funrec: <> ["p"] := let: "p'" := !"p" in letalloc: "r" <- "p'" +â #(T.(ty_size)) in delete [ #1; "p"] ;; return: ["r"]. Lemma snd_type T U `{!TyWf T} `{!TyWf U} : typed_val (snd T U) (fn(â α, â ; &uniq{α} Î [T; U]) â &shr{α} U). Proof. intros E L. iApply type_fn; [solve_typing..|]. iIntros "/= !#". iIntros (α Ï ret p). inv_vec p=>p. simpl_subst. iApply type_deref; [solve_typing..|]. iIntros (p'); simpl_subst. iApply (type_letalloc_1 (&shr{α}U)); [solve_typing..|]. iIntros (r). simpl_subst. iApply type_delete; [solve_typing..|]. iApply type_jump; solve_typing. Qed. End snd.
ããã£ããã¨
lrust.typing.typing
ãã¤ã³ãã¼ãããã¨ããã¦ãlrust.typing.lib.*
ã«Cell
çã®ã©ã¤ãã©ãªãããlrust.typing.examples
ã«ä¾ããã`{typeG Σ}
ã¯å ±éã®ã³ã³ããã¹ãã¨ãã¦åºã¦ãã- ã¾ãMIRãã©ãã
Definition
ã§ä¸ãããã¨ããLemma
ã§åãã¤ããã - ã©ã¤ãã¿ã¤ã ã®å¤ç¸æ§ã¯Î»Rustã§æ±ããã¦ããããåå¤ç¸æ§ã¯ã¡ã¿ã¬ãã«ã§è¡¨ç¾ããã
funrec
ã¯é¢æ°å®ç¾©ã!
ã¯ã¡ã¢ãªãèªããdelete
ã¯ãµã¤ãºã¨å é çªå°ãå¼æ°ã«åããã¼ãã¾ãã¯ã¹ã¿ãã¯ã解æ¾ããã (ãã¼ãã¨ã¹ã¿ãã¯ã¯åçã«æ±ããã)#x
ã¯å®æ°ãªãã©ã«ã+â
ã¯ãã¤ã³ã¿ã¨æ´æ°ã®è¶³ãç®ã- åã¯
type
ã§ãããã¯@type _ H
(H
ã¯åé ã®Context
ã§å®£è¨ããã¦ãããã¤) - ä¸æ£ãªå帰åãé¿ããããã«ãååãwell-formedã§ãããã¨ã®ä¿è¨¼ãæã¡åãå¿
è¦ããããããã¯
`{!TyWf T}
ã§å®ç¾ã§ããã âα, â ; T
ã¯çåæéã«é¢ããéåã§ãâ
ã¯å¤åå¢çããªããã¨ãæå³ãã¦ããã&uniq{α} T
ã¨&shr{α} T
ã¯&'a mut T
ã¨&'a T
ãÎ [A; B; C]
ã¯(A, B, C)
std::mem::size_of::<T>()
ã欲ããã¨ãã¯#(T.(ty_size))
ã¨æ¸ã- unsized typeã®ãµãã¼ãã¯ä»ã®ã¨ãããªãã¦ã
type
ã¯å ¨é¨Sized
ãªåã表ã