Upcoming SlideShare
×

# CoqUn2010

3,097 views

Published on

3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

Views
Total views
3,097
On SlideShare
0
From Embeds
0
Number of Embeds
1,647
Actions
Shares
0
17
0
Likes
3
Embeds 0
No embeds

No notes for slide

• ### CoqUn2010

1. 1. Coq GC ocaml-nagoya / 2010-08-29 Coq 1
2. 2. • • ocaml-nagoya / Proof Cafe • Coq : 11 • GC 2
3. 3. github • github • http://github.com/mzp/gc 3
4. 4. GarbageCollection 4
5. 5. GC50 5
6. 6. (?) ← 6
7. 7. 7
8. 8. GC 8
9. 9. & GC • GC 3 • GC • ” ” • ” ” • A B 9
10. 10. • A ← B D C 10
11. 11. • A ← B D C 10
12. 12. • A ← B D C 10
13. 13. • A ← B D C 10
14. 14. • • A B D C 11
15. 15. • • A B ← D C 11
16. 16. • • A B ← D C 11
17. 17. 12
18. 18. 13
19. 19. M&S ? • • • 14
20. 20. Coq 15
21. 21. Coq • Coq • OCaml Coq/Gallina OCaml ※OCaml 16 Scheme,Haskell
22. 22. 17
23. 23. Record Mem := mkMem { nodes : set A; roots : set A; frees : set A; next : A -> option A; marker : A -> mark; }. 18
24. 24. Record Mem := mkMem { nodes : set A;← roots : set A; frees : set A; next : A -> option A; marker : A -> mark; }. 18
25. 25. Record Mem := mkMem { nodes : set A;← roots : set A;← frees : set A; next : A -> option A; marker : A -> mark; }. 18
26. 26. Record Mem := mkMem { nodes : set A;← roots : set A;← frees : set A;← next : A -> option A; marker : A -> mark; }. 18
27. 27. Record Mem := mkMem { nodes : set A;← roots : set A;← frees : set A;← next : A -> option A; marker : A -> mark; “ ” }. 18
28. 28. Record Mem := mkMem { nodes : set A;← roots : set A;← frees : set A;← next : A -> option A; marker : A -> mark; “ ” }. 18
29. 29. Coq 3 • Prop Ensembles • • List ListSet • • functor FSets • (List,AVL,...) • 19
30. 30. Coq 3 • Prop Ensembles • • List ListSet • • functor FSets • (List,AVL,...) • 19
31. 31. • • • Fixpoint closure (next : A -> option A) (x : A) (xs : set A) : set A := ... 20
32. 32. & 21
33. 33. • • GC • Deﬁnition GC (m1 m2 : Mem) := exists m : Mem, MarkPhase m1 m / SweepPhase m m2. 22
34. 34. • • GC • GC Deﬁnition GC (m1 m2 : Mem) := exists m : Mem, MarkPhase m1 m / SweepPhase m m2. 22
35. 35. • • GC • GC GC Deﬁnition GC (m1 m2 : Mem) := exists m : Mem, MarkPhase m1 m / SweepPhase m m2. 22
36. 36. • • GC • GC GC Deﬁnition GC (m1 m2 : Mem) := exists m : Mem, MarkPhase m1 m / SweepPhase m m2. m1 m 22
37. 37. • • GC • GC GC Deﬁnition GC (m1 m2 : Mem) := exists m : Mem, MarkPhase m1 m / SweepPhase m m2. m1 m m m2 22
38. 38. Deﬁnition MarkPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / frees m1 = frees m2 / next m1 = next m2 / Included (closuresM dec m2) (marksM Marked m2). 23
39. 39. Deﬁnition MarkPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / frees m1 = frees m2 / next m1 = next m2 / Included (closuresM dec m2) (marksM Marked m2). 23
40. 40. Deﬁnition MarkPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / frees m1 = frees m2 / next m1 = next m2 / Included (closuresM dec m2) (marksM Marked m2). ⊆ 23
41. 41. Deﬁnition SweepPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / next m1 = next m2 / frees m2 = union dec (frees m1) (marksM Unmarked m1) / forall (n : A), In n (nodes m2) -> marker m2 n = Unmarked. 24
42. 42. Deﬁnition SweepPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / next m1 = next m2 / frees m2 = union dec (frees m1) (marksM Unmarked m1) / forall (n : A), In n (nodes m2) -> marker m2 n = Unmarked. 24
43. 43. Deﬁnition SweepPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / next m1 = next m2 / frees m2 = union dec (frees m1) (marksM Unmarked m1) / forall (n : A), In n (nodes m2) -> marker m2 n = Unmarked. 24
44. 44. Deﬁnition SweepPhase (m1 m2 : Mem) : Prop := roots m1 = roots m2 / nodes m1 = nodes m2 / next m1 = next m2 / frees m2 = union dec (frees m1) (marksM Unmarked m1) / forall (n : A), In n (nodes m2) -> marker m2 n = Unmarked. 24
45. 45. 25
46. 46. • GC: Deﬁnition Safety (m : Mem) : Prop := Disjoint (frees m) (closuresM dec m). ∩ =Φ • Safety • Safety GC Safety 26
47. 47. • Safety • MarksAll • MarksAll: Lemma MarkPhase_Safety : forall (m1 m2 : Mem), MarkPhase m1 m2 -> Safety m1 -> Safety m2 / MarksAll m2. 27
48. 48. • Safety • MarksAll • MarksAll: Lemma MarkPhase_Safety : forall (m1 m2 : Mem), MarkPhase m1 m2 -> ← m1 m2 Safety m1 -> Safety m2 / MarksAll m2. 27
49. 49. • Safety • MarksAll • MarksAll: Lemma MarkPhase_Safety : forall (m1 m2 : Mem), MarkPhase m1 m2 -> ← m1 m2 Safety m1 -> ← m1 Safety ... Safety m2 / MarksAll m2. 27
50. 50. • Safety • MarksAll • MarksAll: Lemma MarkPhase_Safety : forall (m1 m2 : Mem), MarkPhase m1 m2 -> ← m1 m2 Safety m1 -> ← m1 Safety ... Safety m2 / MarksAll m2. ← m2 Safety MarksAll 27
51. 51. • Safety Lemma SweepPhase_Safety : forall (m1 m2 : Mem), SweepPhase m1 m2 -> Safety m1 -> MarksAll m1 -> Safety m2. 28
52. 52. • Safety Lemma SweepPhase_Safety : forall (m1 m2 : Mem), SweepPhase m1 m2 -> ← m1 m2 Safety m1 -> MarksAll m1 -> Safety m2. 28
53. 53. • Safety Lemma SweepPhase_Safety : forall (m1 m2 : Mem), SweepPhase m1 m2 -> ← m1 m2 Safety m1 -> ← m1 Safety MarksAll m1 -> Safety m2. 28
54. 54. • Safety Lemma SweepPhase_Safety : forall (m1 m2 : Mem), SweepPhase m1 m2 -> ← m1 m2 Safety m1 -> ← m1 Safety MarksAll m1 -> ← m1 MarksAll ... Safety m2. 28
55. 55. • Safety Lemma SweepPhase_Safety : forall (m1 m2 : Mem), SweepPhase m1 m2 -> ← m1 m2 Safety m1 -> ← m1 Safety MarksAll m1 -> ← m1 MarksAll ... Safety m2. ← m2 Safety 28
56. 56. 29
57. 57. Extraction 30
58. 58. Extraction • Extraction Coq OCaml ... 30
59. 59. Extraction • Extraction Coq OCaml ... • 30
60. 60. Require Import List. Extraction “foo.ml” List.length. type nat = |O | S of nat type 'a list = | Nil | Cons of 'a * 'a list (** val length : 'a1 list -> nat **) let rec length = function | Nil -> O | Cons (a, m) -> S (length m) 31
61. 61. Require Import List. Extraction “foo.ml” List.length. type nat = |O | S of nat type 'a list = ← | Nil | Cons of 'a * 'a list OCaml ... (** val length : 'a1 list -> nat **) let rec length = function | Nil -> O | Cons (a, m) -> S (length m) 31
62. 62. • Extract Inductive List.list => "list" ["[]" "(::)"]. • • CoqBase http://sourceforge.jp/projects/ coqbase/ • yoshihiro503++ 32
63. 63. 33
64. 64. • GC • • OCaml 34
65. 65. • Burdy Gemplus Avenue ,  L. Burdy “B vs. Coq to prove a Garbage Collector” 2001 35