Chaperone Contracts for Higher-Order Sessions Hernn Melgratti, - - PowerPoint PPT Presentation

chaperone contracts for higher order sessions
SMART_READER_LITE
LIVE PREVIEW

Chaperone Contracts for Higher-Order Sessions Hernn Melgratti, - - PowerPoint PPT Presentation

Chaperone Contracts for Higher-Order Sessions Hernn Melgratti, Buenos Aires, Argentina Luca Padovani, Torino, Italy Dagstuhl Seminar 17051, 2017 A simple FuSe program let server ep = let p, ep = receive ep in let root = ... in let ep = send


slide-1
SLIDE 1

Chaperone Contracts for Higher-Order Sessions

Hernán Melgratti, Buenos Aires, Argentina Luca Padovani, Torino, Italy

Dagstuhl Seminar 17051, 2017

slide-2
SLIDE 2

A simple FuSe program

let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server

slide-3
SLIDE 3

A simple FuSe program

let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server let user () = let ep = connect math_service in let ep = send (from_list [2.0; -3.0; 1.0]) ep in let _, ep = receive ep in close ep

slide-4
SLIDE 4

A simple FuSe program + Contracts

let server ep = let p, ep = receive ep in let root = ... in let ep = send root ep in close ep let math_service = register server contract "Server" let user () = let ep = connect math_service "Client" in let ep = send (from_list [2.0; -3.0; 1.0]) ep in let _, ep = receive ep in close ep

slide-5
SLIDE 5

Contracts

◮ A contract is a term that describes exchanged messages and

their relationships. flat_c : (t → bool) → [t] t :: ω end_c : [end] send_c : [t] → [T] → [!t.T] receive_c : [t] → [T] → [?t.T] send_d : [t] → (t → [T]) → [!t.T] t :: ω receive_d : [t] → (t → [T]) → [?t.T] t :: ω

slide-6
SLIDE 6

Contracts

let contract = send_c (flat_c (fun p → degree p == 1)) @@ ... (* contract for the continuation *)

slide-7
SLIDE 7

Contracts

let contract = send_c (flat_c (fun p → degree p == 1)) @@ any_c (* contract for the continuation *)

slide-8
SLIDE 8

Contracts

let contract = send_d (flat_c (fun p → degree p == 1)) @@ fun p → receive_c (flat_c (root_of p)) @@ end_c

slide-9
SLIDE 9

Contracts and the structure of the session

choice_c : [bool] → [T] → [S] → [T ⊕S] branch_c : [bool] → [T] → [S] → [T&S]

slide-10
SLIDE 10

Contracts and the structure of the session

ep : !poly.rec A.(?float.A & end)

slide-11
SLIDE 11

Contracts and the structure of the session

ep : !poly.rec A.(?float.A & end) let contract = send_d (flat_c (fun p → degree p > 0)) @@ fun p → let rec missing_roots n = if n > 0 then branch_c any_c (receive_c (flat_c (root_of p)) @@ missing_roots (n - 1)) end_c else branch_c (flat_c not) any_c end_c in missing_roots (degree p)

slide-12
SLIDE 12

First order

Source User Operator x[v1, v2] y[w] y[v1, v2]

x : ?int.?int.end y : !int.!int.?int.end

slide-13
SLIDE 13

First order

Source User Operator x[v1, v2] y[w] y[v1, v2]

x : ?int.?int.end y : !int.!int.?int.end src_c = any_c

  • p_c = send_c any_c @@

send_c (flat_c ( = 0)) @@ receive_c (flat_c ( ≥ 0)) @@ end_c

slide-14
SLIDE 14

Second order

Source User Operator x x[v1, v2] y[w] y[x]

x : ?int.?int.end y :!(?int.?int.end).?int.end

slide-15
SLIDE 15

Second order

Source User Operator x x[v1, v2] y[w] y[x]

x : ?int.?int.end y :!(?int.?int.end).?int.end src_c = any_c

  • p_c = send_c d_c @@

receive_c (flat_c ( ≥ 0)) @@ end_c d_c = receive_c any_c @@ receive_c (flat_c ( = 0)) @@ end_c

slide-16
SLIDE 16

Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]

   E[connect a p] a ⇐c

q v

    → (νs)    E[[s+]c,q,p] (v [s-]dual c,p,q)     | a ⇐c

q v

s fresh

slide-17
SLIDE 17

Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]

   E[connect a p] a ⇐c

q v

    → (νs)    E[[s+]c,q,p] (v [s-]dual c,p,q)     | a ⇐c

q v

s fresh    E[send v [aι]!c;d,σ] E′[receive [aι]?e;f,̺]     →    E[[aι]d,σ] E′[([[v]c,¬σ]e,̺,[aι]f,̺)]    

slide-18
SLIDE 18

Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]

   E[connect a p] a ⇐c

q v

    → (νs)    E[[s+]c,q,p] (v [s-]dual c,p,q)     | a ⇐c

q v

s fresh    E[send v [aι]!c;d,σ] E′[receive [aι]?e;f,̺]     →    E[[aι]d,σ] E′[([[v]c,¬σ]e,̺,[aι]f,̺)]     [v]flat_c w,p,q → v ⊳p wv

slide-19
SLIDE 19

Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]

   E[connect a p] a ⇐c

q v

    → (νs)    E[[s+]c,q,p] (v [s-]dual c,p,q)     | a ⇐c

q v

s fresh    E[send v [aι]!c;d,σ] E′[receive [aι]?e;f,̺]     →    E[[aι]d,σ] E′[([[v]c,¬σ]e,̺,[aι]f,̺)]     [v]flat_c w,p,q → v ⊳p wv v ⊳p true → v v ⊳p false → blame p

slide-20
SLIDE 20

Chaperones [Strickland, Tobin-Hochstadt, Findler & Flatt, 12]

     E[send v [aι]!c;d,σ] E′[receive [aι]?e;f,̺]      →      E[[aι]d,σ] E′[([[v]c,¬σ]e,̺,[aι]f,̺)]     

slide-21
SLIDE 21

Locally correctness & blame safety

◮ p is locally correct in P if

◮ P = Pp[send v [_]!flat_c w;_,_,_] implies v ∈ w, and ◮ P = Pp[send [ε]c,_,_ [_]!d;_,_,_] implies c d, and ... ◮ P → Q implies p is locally correct in Q

slide-22
SLIDE 22

Locally correctness & blame safety

◮ p is locally correct in P if

◮ P = Pp[send v [_]!flat_c w;_,_,_] implies v ∈ w, and ◮ P = Pp[send [ε]c,_,_ [_]!d;_,_,_] implies c d, and ... ◮ P → Q implies p is locally correct in Q

◮ Useful invariant: If P →∗ Pp[send v [_]c,_,q], then q = p

slide-23
SLIDE 23

Locally correctness & blame safety

◮ p is locally correct in P if

◮ P = Pp[send v [_]!flat_c w;_,_,_] implies v ∈ w, and ◮ P = Pp[send [ε]c,_,_ [_]!d;_,_,_] implies c d, and ... ◮ P → Q implies p is locally correct in Q

◮ Useful invariant: If P →∗ Pp[send v [_]c,_,q], then q = p ◮ Blame safety: p is locally correct in P, then P →∗ Q implies

blame p ⊂ Q.

slide-24
SLIDE 24

Final remarks

◮ The language is implemented on top of FuSe

◮ It avoids double checking of contracts ◮ It relies on a small-step semantics for unwinding monitors ◮ Monitors are communicated only when delegating

◮ Communication is restricted to unlimited values and

delegation