Slide 1

Slide 1 text

Types for leak detection in a session-oriented functional programming language Candidato: Andrea Tosatto Relatore: Corelatore: Dott. Luca Padovani Prof. Viviana Bono Tesi di Laurea Triennale in Informatica Types for leak detection in a session-oriented functional programming language Andrea Tosatto 1 / 12

Slide 2

Slide 2 text

Sing# : Copyless message passing E1 E2 msg queue Exchange heap (µ) Threads Types for leak detection in a session-oriented functional programming language Andrea Tosatto 2 / 12

Slide 3

Slide 3 text

Sing# : Copyless message passing E1 E2 msg queue Exchange heap (µ) Threads Types for leak detection in a session-oriented functional programming language Andrea Tosatto 2 / 12

Slide 4

Slide 4 text

Sing# : Copyless message passing E1 E2 msg queue Exchange heap (µ) Threads Types for leak detection in a session-oriented functional programming language Andrea Tosatto 2 / 12

Slide 5

Slide 5 text

A dangerous communication model let (a, b) = open () in close (send a b) Types for leak detection in a session-oriented functional programming language Andrea Tosatto 3 / 12

Slide 6

Slide 6 text

A dangerous communication model let (a, b) = open () in close (send a b) E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 3 / 12

Slide 7

Slide 7 text

A dangerous communication model let (a, b) = open () in close (send a b) a b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 3 / 12

Slide 8

Slide 8 text

A dangerous communication model let (a, b) = open () in close (send a b) a E b Types for leak detection in a session-oriented functional programming language Andrea Tosatto 3 / 12

Slide 9

Slide 9 text

A dangerous communication model let (a, b) = open () in close (send a b) E b Types for leak detection in a session-oriented functional programming language Andrea Tosatto 3 / 12

Slide 10

Slide 10 text

Endpoint Types ?Bool.end !Bool.?Bool.end ?T.end Types for leak detection in a session-oriented functional programming language Andrea Tosatto 4 / 12

Slide 11

Slide 11 text

Types Type t ::= Bool | Unit | t → t | t t | t ⊗ t | T Endpoint Type T ::= end (termination) | !t.T (input) | ?t.T (output) | α (type variable) | rec α.T (recursive type) Types for leak detection in a session-oriented functional programming language Andrea Tosatto 5 / 12

Slide 12

Slide 12 text

Looking at types for detecting leaks let (a, b) = open () in close (send a b) t ::= Bool | Unit | t → t | t t | t ⊗ t | T T ::= end | !t.T | ?t.T | α | rec α.T Types for leak detection in a session-oriented functional programming language Andrea Tosatto 6 / 12

Slide 13

Slide 13 text

Looking at types for detecting leaks let (a, b) = open () in close (send a b) T = !S.end t ::= Bool | Unit | t → t | t t | t ⊗ t | T T ::= end | !t.T | ?t.T | α | rec α.T Types for leak detection in a session-oriented functional programming language Andrea Tosatto 6 / 12

Slide 14

Slide 14 text

Looking at types for detecting leaks let (a, b) = open () in close (send a b) T = !S.end S = ?S.end t ::= Bool | Unit | t → t | t t | t ⊗ t | T T ::= end | !t.T | ?t.T | α | rec α.T Types for leak detection in a session-oriented functional programming language Andrea Tosatto 6 / 12

Slide 15

Slide 15 text

A problematic example let (a, b) = open () in close (send a (g b)) Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 16

Slide 16 text

A problematic example let (a, b) = open () in close (send a (g b)) E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 17

Slide 17 text

A problematic example let (a, b) = open () in close (send a (g b)) a b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 18

Slide 18 text

A problematic example let (a, b) = open () in close (send a (g b)) g b a E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 19

Slide 19 text

A problematic example let (a, b) = open () in close (send a (g b)) g b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 20

Slide 20 text

A problematic example let (a, b) = open () in close (send a (g b)) g b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 21

Slide 21 text

A problematic example let (a, b) = open () in close (send a (g b)) Unit Unit g b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 22

Slide 22 text

A problematic example let (a, b) = open () in close (send a (g b)) Unit Unit g = λx.λy.(fix(λf .λz.f z)x) g b E Types for leak detection in a session-oriented functional programming language Andrea Tosatto 7 / 12

Slide 23

Slide 23 text

Type weight (1) • t = “maximum length of chains of pointers starting from object of type t” • only pointers whose type has finite weight can be sent T = ?Bool.end T = 1 T = ?T.end T = ∞ t = s1 s2 t = ? Types for leak detection in a session-oriented functional programming language Andrea Tosatto 8 / 12

Slide 24

Slide 24 text

Type weight (1) • t = “maximum length of chains of pointers starting from object of type t” • only pointers whose type has finite weight can be sent T = ?Bool.end T = 1 T = ?T.end T = ∞ t = s1 s2 t = ? Types for leak detection in a session-oriented functional programming language Andrea Tosatto 8 / 12

Slide 25

Slide 25 text

Type weight (1) • t = “maximum length of chains of pointers starting from object of type t” • only pointers whose type has finite weight can be sent T = ?Bool.end T = 1 T = ?T.end T = ∞ t = s1 s2 t = ? Types for leak detection in a session-oriented functional programming language Andrea Tosatto 8 / 12

Slide 26

Slide 26 text

Type weight (1) • t = “maximum length of chains of pointers starting from object of type t” • only pointers whose type has finite weight can be sent T = ?Bool.end T = 1 T = ?T.end T = ∞ t = s1 s2 t = ? Types for leak detection in a session-oriented functional programming language Andrea Tosatto 8 / 12

Slide 27

Slide 27 text

Type weight (1) • t = “maximum length of chains of pointers starting from object of type t” • only pointers whose type has finite weight can be sent T = ?Bool.end T = 1 T = ?T.end T = ∞ t = s1 w s2 t = w Types for leak detection in a session-oriented functional programming language Andrea Tosatto 8 / 12

Slide 28

Slide 28 text

Type weight (2) (T-AbsW) Γ, x : t E : s ∀u ∈ dom(Γ) Γ(u) ≤ w Γ λx.E : t w s Types for leak detection in a session-oriented functional programming language Andrea Tosatto 9 / 12

Slide 29

Slide 29 text

Type weight (2) (T-AbsW) Γ, x : t E : s ∀u ∈ dom(Γ) Γ(u) ≤ w Γ λx.E : t w s Types for leak detection in a session-oriented functional programming language Andrea Tosatto 9 / 12

Slide 30

Slide 30 text

Type weight (3) let (a, b) = open () in close (send a (g b)) Types for leak detection in a session-oriented functional programming language Andrea Tosatto 10 / 12

Slide 31

Slide 31 text

Type weight (3) let (a, b) = open () in close (send a (g b)) Unit ∞ Unit Types for leak detection in a session-oriented functional programming language Andrea Tosatto 10 / 12

Slide 32

Slide 32 text

Type weight (3) let (a, b) = open () in close (send a (g b)) Unit ∞ Unit (T-Send) Γ1 E1 : !t.T Γ2 E2 : t t < ∞ Γ1 + Γ2 send E1 E2 : T Types for leak detection in a session-oriented functional programming language Andrea Tosatto 10 / 12

Slide 33

Slide 33 text

Conclusions We have deployed a type system to prevent memory leaks... . . . BUT. . . Does it really work?! Theorem (Soundness) If E is well typed, then E is leak free. Possible extensions • Subtyping... Types for leak detection in a session-oriented functional programming language Andrea Tosatto 11 / 12

Slide 34

Slide 34 text

Conclusions We have deployed a type system to prevent memory leaks... . . . BUT. . . Does it really work?! Theorem (Soundness) If E is well typed, then E is leak free. Possible extensions • Subtyping... Types for leak detection in a session-oriented functional programming language Andrea Tosatto 11 / 12

Slide 35

Slide 35 text

Conclusions We have deployed a type system to prevent memory leaks... . . . BUT. . . Does it really work?! Theorem (Soundness) If E is well typed, then E is leak free. Possible extensions • Subtyping... Types for leak detection in a session-oriented functional programming language Andrea Tosatto 11 / 12

Slide 36

Slide 36 text

Conclusions We have deployed a type system to prevent memory leaks... . . . BUT. . . Does it really work?! Theorem (Soundness) If E is well typed, then E is leak free. Possible extensions • Subtyping... Types for leak detection in a session-oriented functional programming language Andrea Tosatto 11 / 12

Slide 37

Slide 37 text

The End Grazie dell’attenzione! Types for leak detection in a session-oriented functional programming language Andrea Tosatto 12 / 12